excluding custom taxonomy from query on wordpress?

4.6k views Asked by At

I have the following code that lists all the posts from the custom post type "download". I would like to exclude 2 specific categories under a custom taxonomy... (the taxonomy is called "download_category" and the categories i want to hide are called "free-beats" and "sold")

here is the code i have

<?php $temp = $wp_query; $wp_query= null; $wp_query = new WP_Query(); $wp_query->query('post_type=download&showposts=-1'); ?>
<?php while ($wp_query->have_posts()) : $wp_query->the_post(); ?>

I tried adding &download_category=-4 (4 is the id of the free-beats category) and it still didn't work..... any help would be much appreciated

1

There are 1 answers

0
Fabiano Araujo On
$args = array(
    'post_type' => 'download',
    'showposts' => '-1',
    'tax_query' => array(
        array(
            'taxonomy' => 'download_category',
            'field'    => 'id',
            'terms'    => array(4),
            'operator' => 'NOT IN',
        ),
    ),
);
$query = new WP_Query( $args );

From official documentation: http://codex.wordpress.org/Class_Reference/WP_Query#Taxonomy_Parameters