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…
[codesyntax lang=”php”]
function myRSSFilter($query) { if ($query->is_feed) { $query->set('cat','-100'); } return $query; } add_filter('pre_get_posts','myRSSFilter');
[/codesyntax]
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…
[codesyntax lang=”php”]
function myRSSFilter($query) { if ($query->is_feed) { $query->set ('category__not_in', '100' ); } return $query; } add_filter('pre_get_posts','myRSSFilter');
[/codesyntax]
function myFilter($query) { if ($query->is_feed) { $query->set('cat','-99'); } return $query; }[codesyntax lang="php"]
function myRSSFilter($query) { if ($query->is_feed) { $query->set('cat','-100'); } return $query; } add_filter('pre_get_posts','myRSSFilter');[/codesyntax]
add_filter('pre_get_posts','myFilter');
Leave a Comment