0

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); ?>
0

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 );
?>
  • 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 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.