WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

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

I have added query_posts() to my index.php file to modify the loop on the posts page:

query_posts( 'cat=-4,-7' );
get_template_part( 'loop', 'index' );

This works correctly, but when I click on "Older Posts" (link to /page/2), the latest posts show up instead of the previous ones. How can I get my pagination to show the correct posts?

share|improve this question
up vote 2 down vote accepted

different approach:

global $wp_query;
$args = array_merge( $wp_query->query, array( 'category__not_in' => array(4,7) ) );
query_posts( $args );
get_template_part( 'loop', 'index' ); 

if this approach should not work, please check if one or more of the plugins is interfering - deactivate all plugins; if the exclusion of categories works then, re-activate one plugin at a time to find the interfering plugin.

share|improve this answer
That does not actually work. The posts with category 4 or 7 are still showing up. – GavinR Jul 26 '11 at 18:27
answer edited; rewritten with different query parameter. – Michael Jul 27 '11 at 20:10

Use this instead:

global $query_string;
query_posts( $query_string.'&cat=-4,-7' );
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.