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

What is the simplest way to query posts using blog_id?

I have a post type called video that holds, not surprisingly, multiple embedded videos. Each post has a different video.

I would like to display a specific video in specific locations across different sites. The video posts are on Site 1, and other sites in the network could be Site 2, Site 3, Site 4 and Site 5. All sites are in the same multisite setup.

Each video is currently being identified by matching terms in two custom taxonomies, Taxonomy A and Taxonomy B.

If all posts were on the same blog I would use this to query the right video:

$video_query = new WP_Query( array(
    'post_type' => 'video',
    'post_status' => 'publish',
    'posts_per_page' => 1,
    'no_found_rows' => true,
    'tax_query' => array(
        'relation' => 'AND',
            'taxonomy' => 'TaxA',
            'field' => 'slug',
            'terms' => $the_termA
            'taxonomy' => 'TaxB',
            'field' => 'slug',
            'terms' => $the_termB
) );

if( $video_query->have_posts() ) :
    while( $video_query->have_posts() ) :

How can I make the query only look for posts in Site A?

share|improve this question
up vote 4 down vote accepted

Use switch_to_blog() http://codex.wordpress.org/WPMU_Functions/switch_to_blog, do the query and then restore back using restore_current_blog()

share|improve this answer
Awesomeness. Thanks @Ashfame! – mattrepublic Jul 11 '11 at 22:13

switch_to_blog() is not a good solution, because:

This switch is to be used for internal and admin area functions. It's too expensive a query to run on the front end.

You can use WP_Query_Multisite.

Edit: WP_Query_Multisite is also a bad solution, because switch_to_blog() is used in the code as well.

So, I think there is no good solution. :<

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.