How to Get All Taxonomy Terms in WordPress Which Have No Posts

Perhaps you want to get all of the terms in a WordPress taxonomy (categories, tags, a custom taxonomy like WooCommerce’s post_tags or post_categories, etc.) that do not have any posts associated with them. There’s no built in argument that we can pass to get_terms(), though.

To do that, we just use get_terms() and then handle the “no posts” requirement in the foreach() loop, like so:


$args = array(
'taxonomy' => 'your-taxonomy', // change this to the slug of your actual taxonomy
'hide_empty' => false
);
$terms = get_terms($args);
foreach($terms as $term) {
if ($term->count == 0) {
echo $term->count; // or whatever you want to do here
}
}

Enjoy!

Up Next: Pure CSS Avatar / Account / Person Icon