简体   繁体   中英

tax_query not working with WP_Query

i have been trying so hard to make the following code to work but it just doesnt work, I am wondering what could be the reason.

$args = array(
    'post_type' => 'project',
    'tax_query' => array(
                         array(
                               'taxonomy' => 'categories_project',
                               'field' => 'slug'
                         )
                   )
     );
$wp_query = new WP_Query( $args ); 

Running <?php echo $GLOBALS['wp_query']->request; ?> <?php echo $GLOBALS['wp_query']->request; ?> gets me this:

SELECT SQL_CALC_FOUND_ROWS wp_posts.ID 
FROM wp_posts 
INNER JOIN wp_term_relationships 
ON (wp_posts.ID = wp_term_relationships.object_id) 
WHERE 1=1 
AND ( wp_term_relationships.term_taxonomy_id IN (53) ) 
AND wp_posts.post_type = 'project' 
AND (wp_posts.post_status = 'publish' OR wp_posts.post_status = 'private') 
GROUP BY wp_posts.ID ORDER BY wp_posts.post_date DESC 
LIMIT 0, 3

Any help will be highly appreacited. Thanks!

Ok i found of the problem, it needs to have a term!....

$args = array(
    'post_type' => 'project',
    'tax_query' => array(
                     array(
                           'taxonomy' => 'categories_project',
                           **'terms' => $term,**
                           'field' => 'slug'
                     )
               )
    );
$wp_query = new WP_Query( $args ); 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM