WordPress.org

Forums

[resolved] Exclude category with add_filter('pre_get_posts' (3 posts)

  1. picinae
    Member
    Posted 5 years ago #

    function exclude_category($query) {
    if ($query->is_home) {
    $query->set('cat', '-7,-67,-6');
    }
    return $query;
    }
    add_filter('pre_get_posts', 'exclude_category');

    Hi I found this to exclude categories on my index page (home). it works a little bit to good...
    It affects also my 2 sidebars.
    I make the calls in the sidebars with

    query_posts('showposts=30&cat=7,-6');

    How can i make this affectr only my main ?

  2. picinae
    Member
    Posted 5 years ago #

    Sorry I was to fast :P I found this and used it after the main loop

    add_filter('pre_get_posts', 'exclude_category');
  3. picinae
    Member
    Posted 5 years ago #

    Sorry it should be

    remove_filter('pre_get_posts', 'exclude_category');

Topic Closed

This topic has been closed to new replies.

About this Topic