Why tax_query in WP_Query not working


I am using this code to get all posts under the category (name: ‘Quizes’, slug:’quizes’), which is a customized taxonomy (the slug is st_ai_cat).

// the query
$term_name = get_query_var('taxonomy'); // current taxonomy
$cat_name = get_query_var( 'term' ); // curent cat name
    echo $term_name;
    echo $cat_name;
$wp_query = new WP_Query(array('post_type'=>'st_ai',
                               'post_status' => 'publish',
                               'tax_query' => array(
                                      'taxonomy' => $term_name,
                                      'field' => 'slug',
                                      'term' => $cat_name,
if ( $wp_query->have_posts() ) {
    echo "good";

But it always shows nothing. If I remove tax_query, then it can show all posts under the customized taxonomy. But i want to only get posts under the category of Quizes. Why this happens? I checked its usage again.

Thank you.

Shark Deng 4 months 0 Answers 26 views 0

Leave an answer