[resolved] wp_site verses wp_blogs (7 posts)

  1. philipwalton
    Posted 5 years ago #

    I recently set up a test wordpress 3.0 installation on my server, and I'm experimenting with multiple sites. All I really want to do is have multiple blogs in sub-folders, though this question may very well pertain to sub-domains or separate domains as well.

    Here is my question:

    In the wordpress super admin area it shows a listing of my sites; however, in the database there is no mention of these sites in the wp_site table. All I can see is them mentioned in the wp_blogs table. So, what's the difference? And why does the admin refer to them as "sites" when they are referred to in wp_blogs in the database? Am I missing something?

    Also, when I'm doing queries of the database, now I need to know the id of the current blog. Where I used to do something like "SELECT * FROM wp_posts" in my plugin, now I have to do "SELECT * FROM wp_[blog_id]_posts" otherwise I'll always be querying the primary blog.

    However, the function get_current_site() only always returns 1 since that is apparently the only site in my database. Why is there no get_current_blog() function?

    Am I going about this the wrong way? Any help would be greatly appreciated!

  2. David Sader
    Posted 5 years ago #

    $blog_id is a global variable.


    " . $wpdb->base_prefix . $blog_id . "_posts


    $my_posts = $wpdb->get_results( "SELECT * FROM " . $wpdb->base_prefix . $blog_id . "_posts WHERE post_status='publish' AND post_type='post'" );
  3. philipwalton
    Posted 5 years ago #

    Thanks, that's very helpful, but I'm still unclear as to what the difference between a blog and a site in the database is.

    Is a site simply another blog on a different domain using the same wp installation? Would a site with site_id = 2 have tables in the database like wp_2_posts or are the prefixes purely based on the blog_id? What is the relation between the site_id and the blog_id?

  4. It;s wp_blogs as thats what it was in WPMU. It needs to be that way for those upgrading, it has no relation (right now) to the terminology on the front end.

    the site term in the db refers to the network itself. So in MU, you could have multsite sites with their own blogs. in 3.0, you can have multiple networks with their own sites (be they blogs or whatever).

    The prefixes are purely for the blogs.

  5. Andrew Nacin
    Lead Developer
    Posted 5 years ago #

    Use $wpdb->get_blog_prefix( $blog_id ) instead of wp_{$blog_id}... You're making to incorrect assumptions there:

    1. That the installation prefix is wp_.

    2. That the initial blog is wp_1. In 3.0+, it would still be wp_.

  6. philipwalton
    Posted 5 years ago #

    Thanks everyone, this is very helpful.


    If the prefixes are only for blogs, what happens if you have multiple sites? Do they have their own databases, or are multiple sites and blogs in the same database?

  7. They are all in the same db.

Topic Closed

This topic has been closed to new replies.

About this Topic