rainerbrunotte
rainerbrunotte

Reputation: 907

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?

Upvotes: 1

Views: 2095

Answers (2)

aidinMC
aidinMC

Reputation: 1436

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 );

Upvotes: 2

vjy tiwari
vjy tiwari

Reputation: 861

I think you have to use below

taxonomy__not_in => 'linkcategory'

Upvotes: 0

Related Questions