I'm having a dozy of a time on this one and have finally had to break down and ask my first question. Usually I can find an answer on here, but this time I need some help. I'm trying to exclude a category from the main loop so that it does not show up twice on my index page. I have searched up and down and came across this code here:

 $category_id = get_cat_ID('featured');
 $q = 'cat=' . $category_id;
 if (have_posts()) : while (have_posts()) : the_post();


 endwhile; endif;?>

It worked, but then my page navigation didn't work. Even if you clicked on page 2 you still got page one content. Not sure why that happened. I don't want to exclude the category with the ID because the ID will change, but the name will always be the same.

Any help on this would be great, Thanks! If you need the demo site then just ask.


You directly cannot pass the name or slug for excluding a particular category. You have to use the id. Modifying your code:

    $category_id = get_cat_ID('featured');
    //if get_query_var('paged') doesn't work, then try using get_query_var('page') in the next line.
    $paged = (get_query_var('paged'))?get_query_var('paged'):1;
    $q = array();
    $q['category__not_in'] = array($category_id);
    $q['paged'] = $paged;
    if (have_posts()) : while (have_posts()) : the_post();



Hope this helps!

  • I tired it, but I still get the same problem. It will exclude the 'featured' category from the main page, but the navigation will not work. I'm trying to exclude the featured category from the main area on the index page. Below is a link to my wordpress site with the above code in there. tgpwp.com/demoV2 – Steve Oct 4 '11 at 19:33
  • You mean the pagination? I'm modifying the code, check it. – Rutwick Gangurde Oct 5 '11 at 4:34
  • Yes, that one worked. Thank you so much for helping me with this! – Steve Oct 7 '11 at 22:29
  • Awesome! You're welcome! Please mark the answer as correct! – Rutwick Gangurde Oct 8 '11 at 3:31

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.