WordPress How To – Exclude Categories from a Feed

One of the best aspects of WordPress is that it gives you remarkable control over your feeds, allowing you to pick and choose what you would like to display and in what way. Granted, that applies to WordPress in general, but it is infinitely useful for the feeds your system creates.

For instance, if I want to merely show one category in a feed, I would link to feed for that single category. A feed that would only show the reviews of the site is very simple to achive. You go the page main category page (in this example the category is ‘reviews’) and then you add a forward slash (/) and the word ‘feed’. Like this:

http://blog.websitestyle.com/index.php/category/reviews/feed/

However, if you wanted to exclude that category, then you would need to know the number of the category. That is simple enough to find. You would go to your ‘manage’ tab, then click on ‘categories’. Scan down your category list, and you’ll find the number of the category in the associated ‘ID’ column. So now, for the above example, my ‘reviews’ category has an ‘ID’ of 18.

Now each WordPress blog has a feed URL that will display ALL posts from the blog regardless of category. It looks like this:
http://blog.websitestyle.com/index.php?feed=rss2

To exclude all posts in the ‘reviews’ category, you would instead using the following adjustment to your normal feed link:

http://blog.websitestyle.com/index.php?feed=rss2&cat=-18

And now you have a link to a feed that shows all my categories EXCEPT for those in the ‘reviews’ section.

Ah, but what if you want to exclude more than one category? What’s the syntax?

You simply add each one to exclude like this:
This Section Updated
WP Versions Before 2.3.1:
http://blog.websitestyle.com/index.php?feed=rss2&cat=-18&cat=-22
For Version 2.3.1+:
http://blog.websitestyle.com/index.php?feed=rss2&cat=-18,cat=-22

The above would exclude both my ‘reviews’ and ‘templates’ categories. I actually use this when I embed my blog feed in another website that is purely tech (nothing personal included), and I exclude things I’ve categorized as non-tech related so they don’t show up.

Hope this was helpful to someone out there.

~Nicole

12 Replies to “WordPress How To – Exclude Categories from a Feed”

  1. Hi Nicole,

    This is very useful information — I’m trying to create a feed that will automatically exclude all categories that are considered “18+” or offending.

    Would you know how I could provide an entire list of blacklisted categories?

    I would also like to couple this with a .htaccess to rewrite say /sfwrss to the categorical list you showed above.

    Would you have any idea how to do this?

  2. @Eric

    Glad it was helpful!

    I’m not sure I understand what you mean by providing a list of the blacklisted categories – I would imagine that you would have to decide which categories are consider offensive, so that you could then create the exclusions for the feed. You want to be able to list the names of the categories in a feed as excluded? I’m not following your intention.

  3. Hi Nicole,

    I tried to exclude multiple categories by using cat=-1&cat=-2 in the URI, but it only works it you use cat=-1,-2 instead. Just thought I’d let you know.

    Great tutorial too – was exactly what I needed!

  4. @Phil

    Really? How odd. It’s still working for me the way I showed in the example – however, that could be a version issue. I decided to stay with the 2.0.x family of WordPress which will be supported for the next few years, instead of moving on to the 2.1.x version because I didn’t care for the changes in the new one. That could be it. I’m planning to move my blog over to 2.1.x eventually, so I’ll have to check on my testing blog (running 2.1.x) to see if it’s just a version issue. Thanks for the info!

  5. It’s a version issue – I just tested it when I upgraded one of my sites. I’m doing a new design with your exclude tutorial as help for http://kamalaspa.com, and when I did the 2.3.1 upgrade I had to use the comma instead of the ampersand cat=. Just a heads up, thanks for the great tutorial, very efficient and appreciated:) Happy New Year!

  6. Thanks so much for this — it’s really useful.

    Perhaps you would consider updating the main body of the post with the 2.5+ info? It would just make things a bit clearer.

    Thanks again!

Comments are closed.