Excluding Categories from Your WordPress RSS Feed

Chris — March 1, 2009

As a supplement to my previous post about having a separate template for a specific category I thought I should let you know how I excluded a category from a RSS feed.

Say you have a news category that looks different and says something different than the rest of your blog, you might want to exclude that from your RSS feed. I found the following code at WPRecipes (which is down at the time of this writing):

function myFilter($query) {
if ($query->is_feed) {
$query->set('cat','-5'); //Don't forget to change the category ID to what you want
}
return $query;
}

add_filter('pre_get_posts','myFilter');

Place this in your functions.php file. I’m not sure if you can exclude more than one, but my guess is you can just add more category IDs and seperate them with commas: $query->set(‘cat’,'-5,-10,-11′);

No Comments »

RSS feed for comments on this post. TrackBack URL

Leave a comment