Enter your search terms:
Top

Exclude Posts From Your WordPress RSS Feed By Category

WordPress Goodies

I realize this is a VERY specific topic but since it just happened to me, I thought I’d share.

The problem: You’re using WordPress as a CMS and while you’d love for your readers to see all of the great things on your site, there are just some things that don’t need to be pushed to their feed-readers. Like adding new sites to the Portfolio category or adding a second page for contact info or adding a new employee’s bio to the site. While these things are important and your readers may find them later, it’s certainly not news – unless you hired the Dalai Lama or something (great, here come the Chinese hackers).

This also has to do with the structure of your site. Granted, you’ll probably be using Pages for employee bios and contact info but if you’re reading this you’ve probably thought of a reason to filter a category from your feeds. We’re not alone. Smashing Magazine, via Jangro.com and WPRecipes.com have shared the solution and here it is:

“It’s quite simple to do so. Just add the following code to your template’s functions.php file:

function myFilter($query) {
	if ($query->is_feed) {
		$query->set('cat','-5');
	}

return $query;
}

add_filter('pre_get_posts','myFilter');

That will keep category with ID 5 out of the feed.”

You can get the Category ID by going to your Posts > Categories page in your WP admin and hovering over the title of the category you want to exclude. The “ID” number is what you’re looking for. Substitute that in for the number 5 in the above example and you’re all set. Visit Scott Jangro’s site for more about using it for multiple categories and possibly Tags.