impworks Logo - a grinning imp in flight

Removing a Category from WordPress 3.1 RSS Feed

Sunday, February 27th, 2011
4 Comments

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…

  1. function myRSSFilter($query) {
  2. if ($query->is_feed) {
  3. $query->set('cat','-100');
  4. }
  5. return $query;
  6. }
  7.  
  8. 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…

  1. function myRSSFilter($query) {
  2. if ($query->is_feed) {
  3. $query->set ('category__not_in', '100' );
  4. }
  5. return $query;
  6. }
  7.  
  8. add_filter('pre_get_posts','myRSSFilter');

 

function myFilter($query) {
    if ($query->is_feed) {
        $query->set('cat','-99');
    }
return $query;
}
  1. function myRSSFilter($query) {
  2. if ($query->is_feed) {
  3. $query->set('cat','-100');
  4. }
  5. return $query;
  6. }
  7.  
  8. add_filter('pre_get_posts','myRSSFilter');

add_filter('pre_get_posts','myFilter');

Leave a Comment

4 Responses to Removing a Category from WordPress 3.1 RSS Feed

edith Saturday, April 30th, 2011

Thank you so much!
I was looking for hours for a solution!

impworks Friday, March 18th, 2011

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.

Choquj Thursday, March 17th, 2011

Do you think there is a way to filter more than one category at a time ?

amanda Thursday, March 3rd, 2011

Thank you !!!

This has been making me crazy.

impworks © Copyright Mark Caldwell 1996 - 2018