• Home > My Stuff > Removing a Category from WordPress 3.1 RSS Feed

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…

  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');

4 Responses to “Removing a Category from WordPress 3.1 RSS Feed”

  1. Thank you !!!

    This has been making me crazy.

  2. amanda on March 3rd, 2011 at 5:46 pm
  3. Do you think there is a way to filter more than one category at a time ?

  4. Choquj on March 17th, 2011 at 12:58 pm
  5. 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.

  6. impworks on March 18th, 2011 at 1:47 pm
  7. Thank you so much!
    I was looking for hours for a solution!

  8. edith on April 30th, 2011 at 11:24 pm

Please Leave a Comment