I have a CPT with the following taxonomies: category, taxonomy_1 and taxonomy_2 (the last two are non-hierarchical).
I want to get programmatically all the terms of the "category" taxonomy but only of the posts with a given meta value — that meta value is storing the ID of another taxonomy (taxonomy_2
).
So it would be: Categories -> Posts -> Specific meta value
I've tried the following without success:
$args = array(
'meta_query' => array(
'key' => 'taxonomy_key_in_CPT',
'value' => 'value_of_taxonomy_key_in_CPT',
'compare' => "=",
)
)
$categories = get_categories( $args );
But this will still return all the categories under the CPT. Am I doing something funny?
I have a CPT with the following taxonomies: category, taxonomy_1 and taxonomy_2 (the last two are non-hierarchical).
I want to get programmatically all the terms of the "category" taxonomy but only of the posts with a given meta value — that meta value is storing the ID of another taxonomy (taxonomy_2
).
So it would be: Categories -> Posts -> Specific meta value
I've tried the following without success:
$args = array(
'meta_query' => array(
'key' => 'taxonomy_key_in_CPT',
'value' => 'value_of_taxonomy_key_in_CPT',
'compare' => "=",
)
)
$categories = get_categories( $args );
But this will still return all the categories under the CPT. Am I doing something funny?
Share Improve this question edited Dec 5, 2019 at 16:44 darkflamemaster asked Dec 5, 2019 at 15:34 darkflamemasterdarkflamemaster 212 bronze badges1 Answer
Reset to default 0Welcome to WPSE. I believe you are looking for the get_terms()
function. This will return all of the terms for a particular taxonomy, and not the posts.
Pass your taxonomy slug in the array of arguments and set the hide_empty
to false so you get a complete list, like this:
$terms = get_terms( array(
'taxonomy' => 'taxonomy_1',
'hide_empty' => false,
) );
Full documentation can be found code reference: https://developer.wordpress/reference/functions/get_terms/
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744936235a4602042.html
评论列表(0条)