Exclude certain category from latest updates

In addition to the answer by Tim, one can always use a proper tax_query. All the build in tag and category parameters gets converted to a proper tax_query before being passed to the WP_Tax_Query class to build the JOIN clause for the SQL query.

I use a tax_query in almost all applications as it gives one a lot of flexibilty, specially when it comes to child terms, exclusions of multiple terms and even multiple taxonomies. Maybe the only downfall is that you cannot use the string syntax here as in the OP, bacause a tax_query is an array, one should use the array syntax for the query args

In short, to exclude categories, you can try the following

$args = [
    // Your other args
    'tax_query' => [
        [
            'taxonomy'         => 'category',
            'field'            => 'term_id',
            'terms'            => [1,2,3], // Array of term ids to exclude
            'operator'         => 'NOT IN', // Exclude
        'exclude_children' => false // Do not exclude the child terms from the terms defined to exclude
        ]
    ]
];
$postslist = get_posts( $args );

Leave a Comment