In multisite context and WordPress version 4.2.2, with this function in blog_id #3:
switch_to_blog( 2 );
have we really switched in blog_id #2 to fire a query (new WP_Query ( $query ) ;) including a custom taxonomy here (‘domain’) ?
// extract of the query
'tax_query' => array(
'relation' => 'AND',
array(
'field' => 'term_id',
'taxonomy' => 'category',
'terms' => array ('publication', 'evenement'),
'operator' => 'IN'
),
array(
'field' => 'slug',
'taxonomy' => 'domain',
'terms' => array( 'aerien', 'sous-marin'),
'operator' => 'IN'
)
)
In fact NO, because interpreting $query needs the taxonomy to be declared in blog_id #3 where this code is.
A workaround ?
The plugin registering this new taxonomy must not be ‘network activated’ but one by one in #2 and #3 and in properties of this taxonomy, define where the taxonomy must be visible (here #2)
'show_ui' => ($current_blog->blog_id == 2 ) ? true :false,
With this workaround, the deficiency of switch_to_blog( 2 ); is “fixed” and it now possible to display with a custom function (including complex query) in theme of website #3 a list of posts coming from #2.