For sure it’s very simple, but I can not figure out how to do this.
I need to query all posts that has a specific taxonomy set. Like this:
$query03 = array(
'numberposts' => 5,
'post_type' => array(
'video'
),
'tax_query' => array(
array(
'taxonomy' => 'product',
'field' => 'slug',
'terms' => **all_the_terms_in_taxonomy**
)
)
);
I want set the terms
field a wildcard. I know I could populate terms
fild with an array, but the list is very very long and I’m worried about weight of the query.
Have you tried simply omitting the
'terms'
key from the'tax_query'
array?Alternately, I wouldn’t really worry about the weight of the query. The resulting query will be what it will be, regardless of how complex the query args, or how big the query args array. So, I would recommend just pulling in all of your terms via
get_terms
:You can use it directly in your query args array, by setting
'fields'
to'ids'
, which will return an array of term IDs, rather than an array of term objects):Edit
Alternate ‘
tax_query
‘, using term slugs instead of IDs: