Filter your WordPress RSS Feed
I was working on a project last week and needed to use the categories in WordPress to seperate content, but also needed to provide an RSS Feed of only one of the 2 categories. So I did a quick Google – because I figured someone else has probably done this before – and sure enough I found this :
function nameOfFunction($query) {
if ($query->is_feed) {
$query->set('cat','-1');
}
return $query;
}
add_filter('pre_get_posts','nameOfFunction');
Note : the -1 is the category id, I didnt try it but I suppose you could change the category parameters where it says cat to something like category_name and still get the same result.
You could also just change the is_feed to some of the other conditional tags that WordPress has for a different effect.
Thanks to Lucas for suggesting I share this!


Hi. I was using this little trick in my blog, but after an update to 2.9.2 it just doesn’t work anymore, giving me a blank feed.
See this: http://wordpress.org/support/topic/391998?replies=1
What can it be, do you have any idea?
Thanks!
I had this working until last week and then … poof.
(The update to 3.1 seems to be what killed it.)
Interesting, will check this out and let you guys know how to still achieve this!
Hey, any news about this kind of feed?
I need a way to do it.
Use pastebin and post your code here so I can see what you did. According to the WP docs is_feed is still valid, but the setting category part might not be.
is_feed is a function. You are merely checking for its existence. Change it to is_feed() and it should work.
(Yeah, I know, old post)
Yip
but the is_feed object property is already available so no need to call the function, you can just check the object property, unless I’ve missed your point?