WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question

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 );
share|improve this answer

Your Answer


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.