I’m using get_terms
to show a list of terms. It works fine so far.
But I want to hide every term with out of stock products.
If I use 'hide_empty' => true
it wouldn’t work because the products are there and published.
Is there a way to add the _stock
meta field to the get_terms
function?
Unfortunately I have to use get_terms
.
Here’s my code (it’s a lot bigger but that’s the part):
$terms = get_terms( array(
'taxonomy' => 'product_tax',
'orderby' => 'name',
'hide_empty' => true,
) );
2
Answers
5 months ago but maybe it will help someone : I’m facing the same issue and all I found is to make a foreach to unset the empties values.
I’ve recently faced the same issue and ended up doing a native query with $wpdb
Here it is for anyone who needs it: