custom taxonomy - How do I return all terms from multiple taxonomies?

I need to generate a sorted array of all the terms within a set of (six) taxonomies (custom tags) for a custom post type

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?

Share Improve this question asked Jun 12, 2019 at 17:51 Matthew Brown aka Lord MattMatthew Brown aka Lord Matt 1,0683 gold badges13 silver badges34 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 3

You 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

相关推荐

  • custom taxonomy - How do I return all terms from multiple taxonomies?

    I need to generate a sorted array of all the terms within a set of (six) taxonomies (custom tags) for a custom post type

    9小时前
    30

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信