WordPress Alternating main loop (pre_get_posts filter) Exclude category from posts list edit share


Example

add_action( 'pre_get_posts', 'single_category_exclude' );

function single_category_exclude( $query ) {
    if( !$query->is_main_query() || is_admin() ) return;

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