The MU forums have moved to WordPress.org

MU blog-specific table selection (4 posts)

  1. cori
    Member
    Posted 18 years ago #

    I'm hoping that someone with more familiarity than I with the code can point me in the right direction.

    I'm looking at writing a plugin to allow content submitted in one central location to be posted to a specific MU blog and I'm trying to figure out how MU determines which table-prefix to use when inserting to a blog-specific table (for example when using insert_post to insert in the wp_1_posts table). I've found some locations that select table_prefix but I can't tell how the code gets there or how it's told what blog to select the prefix for.

    Anyone have this info somewhere near the top of their head?

    Thanks!

  2. nuprn1
    Member
    Posted 18 years ago #

    Look in wp-settings.php


    $table_prefix = $table_prefix . $blog_id . '_';

    // Table names
    $wpdb->siteid = $site_id;
    $wpdb->blogid = $blog_id;
    $wpdb->posts = $table_prefix . 'posts';
    $wpdb->categories = $table_prefix . 'categories';
    $wpdb->post2cat = $table_prefix . 'post2cat';
    $wpdb->comments = $table_prefix . 'comments';
    $wpdb->links = $table_prefix . 'links';
    $wpdb->linkcategories = $table_prefix . 'linkcategories';
    $wpdb->options = $table_prefix . 'options';
    $wpdb->postmeta = $table_prefix . 'postmeta';
    $wpdb->prefix = $table_prefix;

  3. cori
    Member
    Posted 18 years ago #

    Thanks, I saw that. What I don't grasp is how this gets set when, for example, the publish button on any one blog is ... um ....

    Aha!

    Well, I had looked at the code you pasted before, nuprn1, but hadn't tracked back the $blog_id. Now I see where $blog_id is set earlier in wp_settings.php.

    Thanks for the (re)pointer!

  4. Melodiefabrieknl
    Member
    Posted 17 years ago #

    I have noticed some confusion: when I add a global variable to a mu-plugin plugin, the $table_prefix variable is wp_1_ instead of wp_ when I do request on the homepage (the aggregated page), so it gets overwritten somewhere. Or am I missing something?

    I will create a new post for this, because my comment is not fully related.

About this Topic

  • Started 18 years ago by cori
  • Latest reply from Melodiefabrieknl