I've been tearing my hair out a little trying to get tax_query working in my WP_Query. The code is as follows:
$nextSundayTalkArgs = array(
'post_type' => 'talk',
'posts_per_page' => 1,
'tax_query' => array(
array(
'taxonomy' => 'talk-type',
'field' => 'slug',
'terms' => 'sunday-talk'
)
)
);
$nextSundayTalkQuery = new WP_Query( $nextSundayTalkArgs );
There are definitely posts with the post type of "talk" - if I remove the tax_query part, the correct posts display just fine. There are 5 talks with the correct taxonomy term of "sunday-talk" (and it doesn't work if I try to use IDs instead of slugs, either).
Bizarrely, if I change the post type to "post" and the taxonomy to "category", and leave out the "field" and "terms" part, it comes back with my only post to have no terms on it at all.
Any help greatly appreciated, before I go insane.
<?php echo $GLOBALS['nextSundayTalkQuery']->request; ?>This returns:SELECT SQL_CALC_FOUND_ROWS wp_posts.ID FROM wp_posts WHERE 1=1 AND 0 = 1 AND wp_posts.post_type = 'talk' AND (wp_posts.post_status = 'publish' OR wp_posts.post_author = 1 AND wp_posts.post_status = 'private') GROUP BY wp_posts.ID ORDER BY wp_posts.post_date DESC LIMIT 0, 1- Pete G