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

Basically I have this loop that shows all post. Inside of it I want to exclude post's from categories including shirts and hoodies, also the gallery category. Here is what I have so far.

the code works without the 'cat=-gallery". But with it, it does not show any post's at all.

$limit = 5;
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
query_posts( 'cat=-gallery&showposts=' . $limit . '&paged=' . $paged );
$wp_query->is_category = true; $wp_query->is_home = false;

 <-----my blog stuff---->

<?php endwhile; else: ?>
    <p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
    <?php endif; ?>
    <?php next_posts_link('Older Entries »', 0); ?>
share|improve this question
up vote 0 down vote accepted

When using cat in the query you need to specify the category id not name. Try this.

$gallery = get_cat_id('gallery');
$shirts = get_cat_id('shirts');
$hoodies = get_cat_id('hoodies');
$excluded_cats = '-'.$gallery.',-'.$shirts.',-'.$hoodies;
$limit = 5;
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
query_posts( 'cat='.$excluded_cats.'&showposts=' . $limit . '&paged=' . $paged );
share|improve this answer
ugh. Ive been waiting for you. Thank you. Im new to wp. I was trying to find the id value but figured it would use the name as well. But this worked. Again, thank you! – Nick Nov 28 '11 at 4:23

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.