Let's say I have 3 categories, College (cat=1), Corporate (cat=2), and Idea of the Week (cat=3)

There is a home page for College and a home page for Corporate.

On the College home page, in one section I want to show recent post that is in College but not not in Idea of the Week.

My initial attempt:

<?php query_posts( 'cat=1&cat=-3' ); the_post(); ?>'

but this appears to pull post found in EITHER cat 1 OR cat 3.

Same home page, in a second section I want to show recent post that is in College AND in Idea of the Week.

I'm using:

<?php query_posts( array( 'category__and' => array(1,3), 'posts_per_page=1&orderby=date&order=DESC' )); the_post(); ?>

This seems to work as needed. Is there a similar 'category_and_not' function that I can use for the first query?

1 Answer 1


First, never use query_posts, use WP_Query for additional queries, or pre_get_posts to alter the main query.

Refer to WP_Query in Codex for a complete list of available arguments. You want to use category__not_in in this case:

$args = array(
    'category__in' => array(1),
    'category__not_in' => array(2)
$query = new WP_Query( $args );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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