Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

Thanks!

share|improve this question
add comment

1 Answer 1

up vote 1 down vote accepted
$args = array(
    'posts_per_page' => -1,
    'post_type'      => 'hotwives',
    'post_status'    => 'publish',
    'tax_query'      => array(
        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

share|improve this answer
    
Good stuff. Works perfectly. Thanks for the detailed answer. –  jw60660 Jan 17 '12 at 12:56
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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