How Can You Exclude Categories From Your RSS Feeds?

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.

Related posts

Leave a Reply

3 comments

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