Exclude Category From Home Page, Display Posts on It’s Own Page?

Rather than performing a separate query, to exclude a category (or any other taxonomy) term, you can hook into pre_get_posts:

add_action('pre_get_posts', 'wpse41820_exclude_cat_from_front_page');
function wpse41820_exclude_cat_from_front_page( $query ){
    if( $query->is_main_query() && is_front_page() ){
        $tax_query = array(array(
            'taxonomy' => 'category',
            'field' => 'id',
            'terms' => array( 57 ),
            'operator' => 'NOT IN'
           ));

        $query->set('tax_query',$tax_query);
    }
    return $query;
}

To exclude a slug, alter the $tax_query accordingly:

        $tax_query = array(array(
            'taxonomy' => 'category',
            'field' => 'slug',
            'terms' => array( 'term-slug' ),
            'operator' => 'NOT IN'
           ));

Leave a Comment