I'm having trouble getting post by term in a custom taxonomy I have set up. The catch is this is multisite and I'm getting this data from another blog on the network where the taxonomy is registered. The code I have works fine on the blog with which the taxonomy is registered. However when I try the same code on the other blog using switch_to_blog I get bool(false). Meaning, I guess, that there is an error in the sql. However if I just do is_term I can confirm it's there. Here's a link to the code that is working on the naitive blog but not the other,
<?php get_header(); ?>
<?php global $switched; switch_to_blog(2); ?>
<div class="row-fluid mostwanted-container">
<?php
$type = 'portal_warrants';
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$terms = is_term( 'most-wanted' , 'warrant_status' );
$args=array(
'post_type' => $type,
'posts_per_page' => 6,
'paged' => $paged,
'tax_query' =>
array(
array(
'taxonomy' => 'warrant_status',
'field' => 'id',
'terms' => 'most-wanted',
)
)
);
$my_query = null;
$my_query = new WP_Query($args);
$i = 0;
if( $my_query->have_posts() ) {
while ($my_query->have_posts()) : $my_query->the_post();
if( $i % 3 == 0) :?>
</div>
<div class="row-fluid mostwanted-container">
<?php endif; ?>
<?php print_r(var_dump($wp_query->request)); ?>
<div class="span4 wanted">
<h1>Wanted</h1>
<div class="mostwanted-img">
<img src="http://placehold.it/150x170">
<span class="arrested">Arrested</span>
</div>
<div class="mostwanted-info">
<h3><?php the_title(); ?></h3>
<ul>
<li><strong>Last Known Address:</strong></li>
<li><strong>Hair:</strong></li>
<li><strong>Eyes:</strong></li>
<li><strong>Height:</strong></li>
<li><strong>Weight:</strong></li>
</ul>
</div>
</div>
<?php $i++ ?>
<?php endwhile; } wp_reset_query(); ?>
</div>
<?php restore_current_blog(); ?>
<?php get_footer(); ?>
*Edit (updated pastebin with switch_to_blog included)
Also, this doesn't output anything at all not even with print_r(var_dump($my_query->request));
Solution (or at least in part)
The problem is switch_to_blog
doesn't give you access to everything in another blog on the network including taxonomies, tags, things in your functions.php, although don't quote me 100% on that. Therefore the taxonomy wasn't registered in the "switched to" blog. My solution (at least for now) register the taxonomy in that blog. After doing that, tax_query
worked as expected. This is what I'm going with until I find a better solution (if one exists at all).
switch_to_blog
which was there before but I forgot to put in the Pasebin. The output ofprint_r(var_dump($wp_query->request));
is nothing at all. – jerime May 3 '13 at 20:24tax_query
in the $args I don't get any output. – jerime May 3 '13 at 20:31WP_DEBUG
turned on I get no errors, minusis_term
is depreciated. I can dump the $terms variable and get the correct ID of the term I'm trying to get posts for. – jerime May 3 '13 at 20:40