Exclude posts that only have the ‘Uncategorized’ category [duplicate]

Working off of Pieter Goosen’s answer to this question, the way around this is to create a list of all the categories except the one you want to exclude, then search for posts that include them. That way, if a post has the excluded category but also other categories, it’ll be included. So, in my case:

$args = array ('exclude'=>1,'fields'=>'ids');   
$exclude_uncategorized = get_terms('category',$args);

and then include the following in the $args for the wp_query:

'category__in' => $exclude_uncategorized,

Leave a Comment