admin管理员组文章数量:1426021
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!!
本文标签: custom taxonomyHow do I return all terms from multiple taxonomies
版权声明:本文标题:custom taxonomy - How do I return all terms from multiple taxonomies? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745408773a2657370.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论