I'm writing a query that switches to the main blog of a MU site using switch_to_blog(). All is well except i'm attempting to write a wp_query that includes a variable needed from the previous blog. All the content being pulled from the main blog is stored in a CPT with a taxonomy that corresponds to the various sub-blog names. I'm attempting to store bloginfo('name'); from my previous blog, and pull it into the query after switch_to_blog, but for obvious reasons, no luck (it gets the current bloginfo, not the previous.) Is there any way either to save the the previous bloginfo into a global of some sort, or to switch back to the previous blog just to get that variable mid-query?
See my query below for better illustration:
$location = bloginfo('name');
switch_to_blog( 1 );
$the_query = new WP_Query( array(
'post_type' => 'staff',
'posts_per_page' => -1,
'tax_query' => array(
array(
'taxonomy' => 'location', // name of tax
'field' => 'slug',
'terms' => $location, // this doesn't work, returns nothing
),
),
) ); ?>
<?php if ( $the_query->have_posts() ) : ?>
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<?php endwhile; ?>
<?php wp_reset_postdata(); ?>
<?php else : ?>
<p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
<?php endif; ?>
<?php restore_current_blog(); ?>