• If you want to exclude a category from the main RSS feed and also keep that category rss feed use the following code:

    function ac_exclude_from_rss($query) {
        // Categories to exclude - by ID
        $cats_to_exclude = array( 15, 16);
    
        if ($query->is_feed && !$query->is_category($cats_to_exclude) ) {
            set_query_var('category__not_in', $cats_to_exclude);
        }
    
        return $query;
    }
    add_filter('pre_get_posts','ac_exclude_from_rss');

    If someone has something to add please share ??

Viewing 2 replies - 1 through 2 (of 2 total)
  • Ashok

    (@bappidgreat)

    How about this one?

    function exclude_category($query) {
     if ($query->is_feed) {
       $query->set('cat','-14,-9');
     }
    return $query;
    }
    add_filter('pre_get_posts','exclude_category');

    Thread Starter acosmin

    (@acosmin)

    Yes, that works if you want to exclude some categories from https://yourwebsite.com/feed. It will also disable https://yourwebsite.com/category/acategory/feed which I didn’t wanted.

    My code works in both cases.

    I forgot to mention it was a follow up for this thread.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Exclude category from the main RSS feed and also keep that category feed’ is closed to new replies.