WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Table prefix question with multisite setup (8 posts)

  1. hand_coding
    Member
    Posted 3 years ago #

    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…

  2. Curtiss Grymala
    Member
    Posted 3 years ago #

    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.

  3. hand_coding
    Member
    Posted 3 years ago #

    Hi Curtiss,
    I'm not sure I fully understand the ins and outs of your suggestion but I'll try…

    Thanks a lot…

  4. hand_coding
    Member
    Posted 3 years ago #

    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…

  5. 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.

  6. hand_coding
    Member
    Posted 3 years ago #

    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… :)

  7. 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/

  8. hand_coding
    Member
    Posted 3 years ago #

    :P

Topic Closed

This topic has been closed to new replies.

About this Topic