I need to generate a sorted array of all the terms within a set of (six) taxonomies (custom tags) for a custom post type without any duplicates (of which there are likely to be many).
Is this something get_terms()
can handle and if so, how do I go about doing that? If not, is my best approach 6 calls to get_terms()
followed by an array_merge
?
I need to generate a sorted array of all the terms within a set of (six) taxonomies (custom tags) for a custom post type without any duplicates (of which there are likely to be many).
Is this something get_terms()
can handle and if so, how do I go about doing that? If not, is my best approach 6 calls to get_terms()
followed by an array_merge
?
1 Answer
Reset to default 3You have all sorts of fun questions today!
There is also a WP_Term_Query
available in WordPress. Here is some info on it as well as what parameters you can pass it. https://developer.wordpress/reference/classes/WP_Term_Query/__construct/
$term_args = array(
'taxonomy' => array('tax_one', 'tax_two', 'tax_six'),
'hide_empty' => false,
'fields' => 'all',
'count' => true,
);
$term_query = new WP_Term_Query($term_args);
foreach ( $term_query->terms as $term ) {
// Here is what lives inside of $term when the 'field' parameter above is set to all
/*
WP_Term Object (
[term_id] => 11
[name] => General Topics
[slug] => general-topics
[term_group] => 0
[term_taxonomy_id] => 11
[taxonomy] => category
[description] =>
[parent] => 0
[count] => 22
[filter] => raw
)
*/
// Maybe build out your array() in here to NOT have duplicate Terms ??
}
Hope that helps!!
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745408773a4626434.html
评论列表(0条)