WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am using WordPress 3.2.1 multi-user. I need to show posts from a specific sub domain in my home page, for example: http://mysite.com/sub-blog. I need to show posts from sub-blog in my home page.

Is their any special code to query from a specific blog?

share|improve this question

You're probably going to have to write some custom SQL for that. Here's an example function that would do this. It's slightly insecure as we can't use $wpdb->prepare to put the blog_id in (it surrounds anything inserted with quotes).

function wpse33779_get_posts_from_blog( $blog_id = 1 )
    // is this is the current blog, just get posts...
    if( 1 === $blog_id )
        return get_posts();
        // make sure this is a number.
        $blog_id = absint( $blog_id );

    // did absint kill our blog id?
    if( ! $blog_id ) return array();

    global $wpdb;
    $a = $wpdb->prepare( "SELECT * from {$wpdb->base_prefix}{$blog_id}_posts WHERE 'post' = post_type AND 'publish' = post_status" );
    $posts = $wpdb->get_results( $a );
    return $posts;

I'm not good at writing SQL, but you get the idea. You could flesh that function out to be as full featured as get_posts as well.

You could also use switch_to_blog

switch_to_blog( $blod_id );
$posts = get_posts();
// do stuff with posts

That said, switch_to_blog is probably not a great idea. It's really slow.

share|improve this answer

There are also two plugins you may find useful for this:

ThreeWPBroadcast and WP MU Sitewide tags

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.