WordPress.org

Ready to get started?Download WordPress

Forums

Multisite Table Prefix "$wpdb->prefix" incorrect (6 posts)

  1. jskov
    Member
    Posted 3 years ago #

    I have upgraded a 2.9.1 wpmu installation to WP 3.0.1 MS.

    Now, I am having issues with the $wpdb->prefix reference in a few plugins. It seems to pull an individual blog's prefix (ie. wp_#_ ) rather than the site prefix (ie. wp_ ).

    Is this correct? Is there something else that should be used instead? Is there something I am missing?

  2. Leon
    Member
    Posted 3 years ago #

    I was just having a similar problem.

    You can get the variable out of wp-config.php >> $table_prefix
    which is bij default 'wp_'
    So I thought I could be using that as site prefix, but apparantly wordpress adds '#_' to this as well...

    So when you do the following on a plugin:

    global $table_prefix;
    var_dump( $table_prefix );

    it outputs 'wp_#_';

    But I also need it to output 'wp_';

    hope someone can explain.

  3. David Gard
    Member
    Posted 3 years ago #

    The following will give you just the wp_ part.

    global $wpdb;
    print_r($wpdb->base_prefix);
  4. Leon
    Member
    Posted 3 years ago #

    Much appreciated! That does the trick for me!

  5. David Gard
    Member
    Posted 3 years ago #

    No worries - If you are referencing a pre-existing table you can also use the $wpdb class to call the name of the table (including the correct base-prefix/prefix) For example, on my companies Client Balances site $wpdb->posts would return 'wp_2_posts' and $wpdb->users would return 'wp_users' - Very handy!

  6. jskov
    Member
    Posted 3 years ago #

    Sweet. I'll give it a try

Topic Closed

This topic has been closed to new replies.

About this Topic