• Resolved roxer82

    (@roxer82)


    Hello,
    I need to exclude some categories from main feed, so I added

    $posts = query_posts(‘cat=-1,-5,-8’);

    before

    while( have_posts()) : the_post();

    in feed-rss2.php
    It worked, but now, categories and tags feeds show the main feed.
    ie: mysite.com/tag/moon/feed/ shows the same as mysite.com/feed/.
    Do you know how to exclude categories but keeping the feed’s functionality?
    Thanks.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Hmmm… I think this function should do the trick:

    function exclude_my_cat($query) {
     if ($query->is_feed) {
       $query->set('cat','-1,-5,-8');
     }
    return $query;
    }
    add_filter('pre_get_posts','exclude_my_cat');

    You should run it from your Child Theme functions.php file.

    You should NEVER edit core WP, theme, or plugin files. The changes will be over-written anytime you update.

    Thread Starter roxer82

    (@roxer82)

    Thank you very much Josh! It works perfect.
    And I’ll take your advice about WP core.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Exclude categorys from feed but keeping functionality’ is closed to new replies.