Exclude Single Category in WordPress

Exclude Single Category in WordPress

If you ever need to exclude a single category from a WordPress page (archives, index, category page, etc) you can easily do so by using a little conditional tag code within the WordPress loop.

The example below will skip over any post that is in the category with the ID of 35:





This can be helpful if you want to not show a particular category in your blog (if you have a category based site setup) – or if you want to hide some categories from your search results.

7 thoughts on “Exclude Single Category in WordPress”
  1. robert |

    That should be IN, not IS, in_category

  2. jzelazny |

    Good catch – I have corrected my mistype.

  3. Aleksey |

    Not working with version 2.6.1 . And I don’t know why…

  4. jzelazny |

    It is still working fine for me in 2.6.1. Feel free to email me (see contact form) with your theme file if you want some input.

  5. Mudassar Ijaz |

    To exclude a category from the loop on the front page, find this code:

    and change it to this:

    This will exclude posts in category number four from being displayed on the front page.

    NOTE: This will also solve previous and next entry links ( pagination ) with above code.

  6. Mudassar Ijaz |

    Sorry posting again as it isn’t showing code

    To exclude a category from the loop on the front page, find this code:

    and change it to this:


    This will exclude posts in category number four from being displayed on the front page.

  7. Adam Fehnel |

    Quick question, I noticed that when I use this code I’m having an issue with getting the right number of posts to display. Example, I have default settings to show most recent 10 posts. I have 13 posts, 3 in the blog category I want to show up, and 10 in the hidden category I don’t want to show up. If the 10 posts I don’t want to show up are more recent than the 3 I do want, nothing shows up on the home page because the loop still counts posts you “continue;” and then doesn’t show the 3 I want.

    Any ideas for this issue?

    Thanks,

    -Adam

Leave a Reply

Your email address will not be published.
*
*

This site uses Akismet to reduce spam. Learn how your comment data is processed.