I have a custom loop from a custom post type and I want to NOT display posts with the category 'slider'.

I'm using this to set up the query:

$args = array( 'post_type' => 'hotwives', 'posts_per_page' => -1);
$loop = new WP_Query( $args );
while ($loop->have_posts() ) : $loop->the_post();

I was going to use this in the $args variable:

'category' => 'slider'

But not sure how to make that NOT display the posts from category 'slider'.

And, incidentally, when I use that in the $args variable it still shows every post, not just the 'slider' posts. So, seems I'm not on the right track regardless.


1 Answer 1

$args = array(
    'posts_per_page' => -1,
    'post_type'      => 'hotwives',
    'post_status'    => 'publish',
    'tax_query'      => array(
            'taxonomy' => 'category',
            'field'    => 'slug',
            'terms'    => 'slider',
            'operator' => 'NOT IN'

Use that as the args for your WP_Query and you should get posts that aren't in the category taxonomy. It also has the advantage of being expansible to more than one exclude, etc. If you're using a custom taxonomy, change 'taxonomy''s value to the name of that taxonomy.

Docs: WP_Query

  • Good stuff. Works perfectly. Thanks for the detailed answer.
    – jw60660
    Jan 17, 2012 at 12:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.