Removing a Category from WordPress 3.1 RSS Feed
February 27, 2011 8:47 pm
I filter a category out of my WordPress RSS feed because it’s all my tweets from the week. I want an archive (mostly for myself) but I don’t want to blast anyone following my RSS feed with them every week. I’d been using code like this in functions.php in my theme to screen them…
- function myRSSFilter($query) {
- if ($query->is_feed) {
- $query->set('cat','-100');
- }
- return $query;
- }
-
- add_filter('pre_get_posts','myRSSFilter');
Where the category has an ID of 100 so you put -100 in the code.
This doesn’t work in WordPress 3.1 and I’d not come across a fix so I did a bit of experimenting and found that this code seems to remove the unwanted category from the feed…
- function myRSSFilter($query) {
- if ($query->is_feed) {
- $query->set ('category__not_in', '100' );
- }
- return $query;
- }
-
- add_filter('pre_get_posts','myRSSFilter');
function myFilter($query) {
if ($query->is_feed) {
$query->set('cat','-99');
}
return $query;
}- function myRSSFilter($query) {
- if ($query->is_feed) {
- $query->set('cat','-100');
- }
- return $query;
- }
-
- add_filter('pre_get_posts','myRSSFilter');
add_filter('pre_get_posts','myFilter');
4 Responses to “Removing a Category from WordPress 3.1 RSS Feed”



Thank you !!!
This has been making me crazy.
Do you think there is a way to filter more than one category at a time ?
Amanda – there may be but after a few quick experiments I’ve not been able to find a way to do this. I’m guessing it involves passing multiple values to
$query->set (‘category__not_in’, ’100′ ) but it may be more complex than that.
Thank you so much!
I was looking for hours for a solution!