I've been having a lot of trouble getting a
WP_Query running with a
tax_query on my custom taxonomy.
I'm 99.9% sure that my
register_taxonomy is correct, as I'm able to tag posts with the right term, see it in the database, and the correct term returns with an
But when I use a
tax_query in my
WP_Query, I get no posts. If I look at the echo of
$GLOBALS['nextSundayTalkQuery']->request;, I get the following:
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
I've tried no end of solutions, asked for help in several places, and have had no luck. I'm posting again for help with slightly updated information, so hopefully this time I might find an answer.
WP_Query looks like this:
$nextSundayTalkArgs = array( 'post_type' => 'talk', 'posts_per_page' => 1, 'tax_query' => array( array( 'taxonomy' => 'talktype', 'field' => 'slug', 'terms' => 'sunday-talk' ) ) ); $nextSundayTalkQuery = new WP_Query( $nextSundayTalkArgs );
It works perfectly without 'tax_query'. If I use something like
'talktype' => 'sunday-talk' instead, using
query_var when I register the taxonomy, it simply ignores the line as thought it weren't there and prints any talk (instead of saying "no posts").
Using identical code to query WordPress' default "category" taxonomy works fine, so it seems to be related to my custom taxonomy or post type. To save space on this post, my custom post type code is here:
and my custom taxonomy code is here:
I would appreciate any and all help, as this problem has been unsolvable for months with many people trying (and failing, unfortunately) to figure out what's wrong.