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.

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.

<?php
$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

1 Answer 1

up vote 0 down vote accepted

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

<?php
$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

 
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.