• Hi, for a Project i need to exclude some categories from some pages.

    First i used this Code in the Theme functions.php:

    // remove from home page
    function exclude_category($query) {
    if ( $query->is_home ) {
    $query->set('cat', '-26');
    }
    return $query;
    }
    add_filter('pre_get_posts', 'exclude_category');
    // remove from home page

    This exclude the cat from all Pages. But it works.
    Then i try this:

    // remove from home page
    function exclude_category($query) {
    if ( $query->is_page( array( 5, 83 ) ) ) {
    $query->set('cat', '-26');
    }
    return $query;
    }
    add_filter('pre_get_posts', 'exclude_category');
    // remove from home page

    but this dont works. Any idea why?

    Thx for help

  • The topic ‘Exclude Category from some pages’ is closed to new replies.