Title: Exclude category from the loop?
Last modified: August 18, 2016

---

# Exclude category from the loop?

 *  Resolved [Austin Matzko](https://wordpress.org/support/users/filosofo/)
 * (@filosofo)
 * [20 years ago](https://wordpress.org/support/topic/exclude-category-from-the-loop/)
 * I’d like to exclude all posts of a certain category from appearing on the front
   page, although I would like to be able to view them as single entries.
 * However, I _also_ need to preserve the maximum number of posts shown per “blog
   page,” which you can set under Options > Reading.
 * The problem with the approach [outlined here](http://codex.wordpress.org/The_Loop#Exclude_Posts_From_Some_Category)
   is that if you’re excluding posts of category 3, if your max number of posts 
   shown per page is 10, and if 8 of the 10 most recent posts are of category 3,
   then you’ll end up with only 2 posts on your first page, instead of 10.
 * What can I do to get around this?
 * Thanks for your help.

Viewing 13 replies - 1 through 13 (of 13 total)

 *  Moderator [Samuel Wood (Otto)](https://wordpress.org/support/users/otto42/)
 * (@otto42)
 * WordPress.org Admin
 * [20 years ago](https://wordpress.org/support/topic/exclude-category-from-the-loop/#post-382466)
 * Check out this plugin: [http://ryowebsite.com/?p=46](http://ryowebsite.com/?p=46)
 * It lets you exclude categories from the front page, archives, rss, etc.. It also
   satisfies your requirement of not limiting the number of posts when it excludes
   them.
 *  Thread Starter [Austin Matzko](https://wordpress.org/support/users/filosofo/)
 * (@filosofo)
 * [20 years ago](https://wordpress.org/support/topic/exclude-category-from-the-loop/#post-382626)
 * Thanks Otto42. That plugin did some stuff I didn’t want, but it helped by pointing
   me in the right direction.
 * Actually, I discovered that there’s a pretty simple plugin fix to do what I want,
   _as long as you’re using MySQL 4.1 or newer_ (older versions don’t work because
   they don’t support subqueries):
 * `function modify_where_clause($where) {
    global $wp_query, $wpdb; if ($wp_query-
   >is_home && !strstr($where,'category_id')) $where .= " AND ID NOT IN (SELECT 
   post_id FROM $wpdb->post2cat WHERE category_id=2)"; return $where; } add_filter('
   posts_where','modify_where_clause');
 * This removes all posts of category id 2 from the loop and doesn’t interfere with
   specific requests you might have for category 2 (in my case, a sidebar blog of
   only category 2 entries).
 *  [ryoken](https://wordpress.org/support/users/ryoken/)
 * (@ryoken)
 * [20 years ago](https://wordpress.org/support/topic/exclude-category-from-the-loop/#post-382629)
 * can’t you use query_posts to handle this as well?
 *  Thread Starter [Austin Matzko](https://wordpress.org/support/users/filosofo/)
 * (@filosofo)
 * [20 years ago](https://wordpress.org/support/topic/exclude-category-from-the-loop/#post-382639)
 * How?
 *  [ryoken](https://wordpress.org/support/users/ryoken/)
 * (@ryoken)
 * [20 years ago](https://wordpress.org/support/topic/exclude-category-from-the-loop/#post-382659)
 * [http://codex.wordpress.org/Template_Tags/query_posts](http://codex.wordpress.org/Template_Tags/query_posts)
 * I don’t know if that info is outdated but it has worked for me.
 *  Thread Starter [Austin Matzko](https://wordpress.org/support/users/filosofo/)
 * (@filosofo)
 * [20 years ago](https://wordpress.org/support/topic/exclude-category-from-the-loop/#post-382667)
 * Okay, I see what you’re saying. The problem is that something like `query_posts("
   cat=-3");` excludes a post of category 3 only if that post is under _just_ category
   3. If you’ve assigned it other categories, then it’s not excluded.
 *  [mae](https://wordpress.org/support/users/mae/)
 * (@mae)
 * [19 years, 8 months ago](https://wordpress.org/support/topic/exclude-category-from-the-loop/#post-382740)
 * [@filosofo](https://wordpress.org/support/users/filosofo/): where would I put
   that code? I’m having problems with that as well…
 *  Thread Starter [Austin Matzko](https://wordpress.org/support/users/filosofo/)
 * (@filosofo)
 * [19 years, 8 months ago](https://wordpress.org/support/topic/exclude-category-from-the-loop/#post-382741)
 * mae, you could put it in your theme’s functions.php file.
 *  [mae](https://wordpress.org/support/users/mae/)
 * (@mae)
 * [19 years, 8 months ago](https://wordpress.org/support/topic/exclude-category-from-the-loop/#post-382742)
 * yes! it worked! thanks a lot filosofo!
 *  [highwind](https://wordpress.org/support/users/highwind/)
 * (@highwind)
 * [19 years, 5 months ago](https://wordpress.org/support/topic/exclude-category-from-the-loop/#post-382758)
 * How would you modify the where clause for the RSS feeds?
 *  [gerld](https://wordpress.org/support/users/gerld/)
 * (@gerld)
 * [19 years, 5 months ago](https://wordpress.org/support/topic/exclude-category-from-the-loop/#post-382759)
 * i have the same question as highwind.
 * ALSO.. i’ve managed to use a few ifelse statements to exclude the categories 
   i want from the loop, but i have the same problem as the original poster in this
   thread.
 * how can i exclude the categories but still preserve the recent post count ??
 *  [gerld](https://wordpress.org/support/users/gerld/)
 * (@gerld)
 * [19 years, 5 months ago](https://wordpress.org/support/topic/exclude-category-from-the-loop/#post-382760)
 * i’m assuming i could use this code… but how would i modify it to exclude multiple
   categories ?
 * function modify_where_clause($where) {
    global $wp_query, $wpdb; if ($wp_query-
   >is_home && !strstr($where,’category_id’)) $where .= ” AND ID NOT IN (SELECT 
   post_id FROM $wpdb->post2cat WHERE category_id=2)”; return $where; } add_filter(‘
   posts_where’,’modify_where_clause’);
 * also, i’m not sure exactly where to put that little bit of code, or how to call
   it. can anyone help ?
 *  [haarball](https://wordpress.org/support/users/haarball/)
 * (@haarball)
 * [19 years, 2 months ago](https://wordpress.org/support/topic/exclude-category-from-the-loop/#post-382763)
 * I’m sort of wondering about the same thing. I want to INCLUDE multiple categories,
   or more correctly, I want to do this more than one time on the same page (as 
   outlined [here](http://wordpress.org/support/topic/108703?replies=1#post-526452)).
 * Possible?

Viewing 13 replies - 1 through 13 (of 13 total)

The topic ‘Exclude category from the loop?’ is closed to new replies.

## Tags

 * [categories](https://wordpress.org/support/topic-tag/categories/)
 * [loop](https://wordpress.org/support/topic-tag/loop/)

 * 13 replies
 * 7 participants
 * Last reply from: [haarball](https://wordpress.org/support/users/haarball/)
 * Last activity: [19 years, 2 months ago](https://wordpress.org/support/topic/exclude-category-from-the-loop/#post-382763)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
