Title: Table prefix question with multisite setup
Last modified: August 19, 2016

---

# Table prefix question with multisite setup

 *  Resolved [hand_coding](https://wordpress.org/support/users/hand_coding/)
 * (@hand_coding)
 * [15 years, 3 months ago](https://wordpress.org/support/topic/table-prefix-question-with-multisite-setup/)
 * Hi,
    I’ve set up a WordPress site with 14 blogs. The table prefix for the main
   blog is just “wp_” while for the other blogs it’s “wp_” + the blog_id, starting
   at “2”, so I have tables named “wp_posts”, “wp_2_posts”, “wp_3_posts” etc.
 * This causes a problem with a plugin whose task is to collect the latest post 
   from every blog. The call to mysql is a foreach loop and looks like “wp_”.$blogid.”
   _posts” which obviously returns nothing for the main site.
 * Is there a way to set the table prefix for the main site to “wp_1_” in place 
   of just “wp_”?
 * Thanks…

Viewing 7 replies - 1 through 7 (of 7 total)

 *  [Curtiss Grymala](https://wordpress.org/support/users/cgrymala/)
 * (@cgrymala)
 * [15 years, 3 months ago](https://wordpress.org/support/topic/table-prefix-question-with-multisite-setup/#post-1963428)
 * This is an issue with the way the plugin is written. It needs to be updated to
   use the proper functions.
 * If you want to update the plugin yourself, you should replace all instances of`"
   wp_".$blogid."_posts"` with `$wpdb->posts`. That way, even if you use a prefix
   other than “wp_” when you install WordPress, the plugin will still work properly.
   You should then use the `$wpdb->set_blog_id()` function to switch from one blog
   to another.
 *  Thread Starter [hand_coding](https://wordpress.org/support/users/hand_coding/)
 * (@hand_coding)
 * [15 years, 3 months ago](https://wordpress.org/support/topic/table-prefix-question-with-multisite-setup/#post-1963434)
 * Hi Curtiss,
    I’m not sure I fully understand the ins and outs of your suggestion
   but I’ll try…
 * Thanks a lot…
 *  Thread Starter [hand_coding](https://wordpress.org/support/users/hand_coding/)
 * (@hand_coding)
 * [15 years, 3 months ago](https://wordpress.org/support/topic/table-prefix-question-with-multisite-setup/#post-1963483)
 * Well… I was unable to find a way to implement your suggestion in a query like`"
   SELECT post_content FROM " . "wp_" . $blogid . "_posts" …` so I ended up with
   adding a variable based on the blog id: `$wp_bid = $blogid == 1 ? "wp" : "wp_".
   $blogid;` so the query is now:`"SELECT post_content FROM " . $wp_bid . "_posts"…`.
 * It works nicely.
    Thanks again…
 *  [Andrea Rennick](https://wordpress.org/support/users/andrea_r/)
 * (@andrea_r)
 * [15 years, 3 months ago](https://wordpress.org/support/topic/table-prefix-question-with-multisite-setup/#post-1963553)
 * > This causes a problem with a plugin whose task is to collect the latest post
   > from every blog.
 * Find another plugin for this. there are plenty.
 * Any plugin specifically written for multisite already knows about the table prefixes.
   If this plugin does that, then it’s just bad coding, or wasn’t written for multisite.
 *  Thread Starter [hand_coding](https://wordpress.org/support/users/hand_coding/)
 * (@hand_coding)
 * [15 years, 3 months ago](https://wordpress.org/support/topic/table-prefix-question-with-multisite-setup/#post-1963559)
 * I don’t think it’s bad coded; it’s just not flexible…
    “list-all-posts” was designed
   for WordPress-mu and was, at the time, a free gift from WPMU Dev along with “
   list-all”, designed to retrieve every blogs in a WP-mu install. Those are nowhere
   to be found now, it seems…
 * Lucky you are if you found “plenty” of WP plugins for this, because I did a lot
   of search… 🙂
 *  [Andrea Rennick](https://wordpress.org/support/users/andrea_r/)
 * (@andrea_r)
 * [15 years, 3 months ago](https://wordpress.org/support/topic/table-prefix-question-with-multisite-setup/#post-1963560)
 * becasue those were developed over 2-3 years ago and not touched since.
 * > Lucky you are if you found “plenty” of WP plugins for this, because I did a
   > lot of search…
 * Guess you completely missed my site then.
 * [http://wpmututorials.com/how-to/return-a-list-of-sites-on-the-network/](http://wpmututorials.com/how-to/return-a-list-of-sites-on-the-network/)
 *  Thread Starter [hand_coding](https://wordpress.org/support/users/hand_coding/)
 * (@hand_coding)
 * [15 years, 3 months ago](https://wordpress.org/support/topic/table-prefix-question-with-multisite-setup/#post-1963562)
 * 😛

Viewing 7 replies - 1 through 7 (of 7 total)

The topic ‘Table prefix question with multisite setup’ is closed to new replies.

## Tags

 * [multisite](https://wordpress.org/support/topic-tag/multisite/)
 * [table-prefix](https://wordpress.org/support/topic-tag/table-prefix/)

 * In: [Networking WordPress](https://wordpress.org/support/forum/multisite/)
 * 7 replies
 * 3 participants
 * Last reply from: [hand_coding](https://wordpress.org/support/users/hand_coding/)
 * Last activity: [15 years, 3 months ago](https://wordpress.org/support/topic/table-prefix-question-with-multisite-setup/#post-1963562)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
