简体   繁体   中英

Wordpress exclude custom taxonomy category from WP Query

I am trying to exclude posts from a custom post type that have a specific taxonomy category, however they keep showing up:

<?php
$args = array(
'post_type' => 'info_link',
'taxonomy' => 'linkcategory',
'terms' => 'featured',
'operator' => 'NOT IN',
'orderby' => 'title',
'order' => 'ASC',
'posts_per_page' => '100',
);
query_posts($args);
if ( have_posts() ) : while ( have_posts() ) : the_post();
...
?>

However it does not work. I have also tried "NOT EXISTS" as an operator, but they still show up. Where is my mistake?

The answer is in WP_Query documentation

$args = array(
    'post_type' => 'info_link',
    'tax_query' => array(
        array(
            'taxonomy' => 'linkcategory',
            'field'    => 'slug',
            'terms'    => 'featured',
            'operator' => 'NOT IN',
        ),
    )
);
$query = new WP_Query( $args );

我认为你必须在下面使用

taxonomy__not_in => 'linkcategory'

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