2

I've searched and found posts that have asked and answered how to merge different categories into an RSS feed. What I need to know is how to exclude specific categories from the RSS feed?

Specifically, I use WP to post blog articles and to post portfolio items onto my site. I want to exclude the portfolio category from appearing in the RSS feed, making only blog posts available.

0

It's been broken since 3.1, see:
http://core.trac.wordpress.org/ticket/16622
and also
http://wordpress.org/support/topic/wp-31-breaks-rss-customization-via-exclude_category NOTE: Otto's suggested fix in that thread doesn't work for me.

Ticket suggests patch will go in for 3.1.1 and i can confirm that currently filters on pre_get_posts or parse_query fail for feeds(unfortunately).

0

Not too confident to get hooks right from memory... I think hooking into pre_get_posts and setting category__not_in to what you want to skip on is_feed() conditional should work.

But might require playing with different hooks earlier/later, querying internals are confusing around there.

0
function wpsites_exclude_category_rss_feed($query) {
 if ($query->is_feed) {
   $query->set('cat','-007,-008');
 }
return $query;
}
add_filter('pre_get_posts','wpsites_exclude_category_rss_feed');

Either of these snippets in your functions file will work using pre_get_posts

function wpsites_exclude_category_rss_feed($query) {
if ( $query->is_feed) {
    $query-> set('category__not_in',array(007));
    }
return $query;
}
add_filter('pre_get_posts','wpsites_exclude_category_rss_feed');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.