• Resolved philipwalton

    (@philipwalton)


    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!

Viewing 6 replies - 1 through 6 (of 6 total)
  • $blog_id is a global variable.

    https://www.ads-software.com/support/topic/317883

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

    Example

    $my_posts = $wpdb->get_results( "SELECT * FROM " . $wpdb->base_prefix . $blog_id . "_posts WHERE post_status='publish' AND post_type='post'" );

    Thread Starter philipwalton

    (@philipwalton)

    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?

    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.

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

    Thread Starter philipwalton

    (@philipwalton)

    Thanks everyone, this is very helpful.

    @andrea_r

    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?

    They are all in the same db.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘wp_site verses wp_blogs’ is closed to new replies.