获取所选自定义分类的名称

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了获取所选自定义分类的名称相关的知识,希望对你有一定的参考价值。

Use this to get the name of the custom taxonomy. Note that this only returns the name of the first selected item, but since this returns an array, use a foreach loop to find all names.
  1. // get name of manufacturer of this post
  2. // replace 'manufacturer' with the id name of your custom taxomony
  3. $manufacturer = wp_get_post_terms($post->ID, 'manufacturer');
  4. $manufacturer_name = $manufacturer[0]->name;
  5.  
  6. // use this to display the name
  7. echo $manufacturer_name;

以上是关于获取所选自定义分类的名称的主要内容,如果未能解决你的问题,请参考以下文章