Tax_Query doesn't work with WP_Query

I ripped my hair a bit while trying to get tax_query to work in my WP_Query. The code looks like this:

$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 certain posts with the post type "talk" - if I remove the tax_query part, the correct posts are displayed just fine. There are 5 conversations with the correct taxonomy term "Sunday Talk" (and it doesn't work if I try to use IDs instead of bullets).

Unusually, 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 so that it doesn't have any strings attached at all.

Any help is greatly appreciated before I go crazy.

+3


source to share


2 answers


Eventually found the answer with some help on the Wordpress Stackexchange. Still not 100% sure what I was doing wrong, but it seems to be a problem with both the function layout and the post loop I used in index.php

.

For those who come across this question and are interested:



https://wordpress.stackexchange.com/questions/84607/custom-taxonomy-and-tax-query

+5


source


I'm not sure about your answer, but I'll try first and figure out what database query your code is calling.

https://wordpress.stackexchange.com/questions/4809/how-to-display-sql-query-that-ran-in-query



This is a link to various ways to debug a query. This helps a lot as you can see what it does, can run it on phpmyadmin, etc.

+1


source







All Articles