首页 WordPress函数 WordPress根据文章ID获取分类法对象函数:wp_get_object_terms
正文 评论

WordPress根据文章ID获取分类法对象函数:wp_get_object_terms

WordPress函数wp_get_object_terms根据文章的ID获取分类法对象,主要在自定义分类法时使用,获取Category可以使用get_the_category()函数。

wp_get_object_terms( int|int[] $object_ids, string|string[] $taxonomies, array|string $args = array() )

函数参数

$object_ids

整数

文章ID

$taxonomies

字符串

分类法名称

$args

数组,参数可用值参考get_categories()函数的$args参数说明

函数返回值

Array(    [0] => WP_Term Object        (            [term_id] => 2            [name] => 开发            [slug] => develop            [term_group] => 0            [term_taxonomy_id] => 2            [taxonomy] => category            [description] =>             [parent] => 1            [count] => 100            [filter] => raw        )    [1] => WP_Term Object        (            [term_id] => 3            [name] => 教程            [slug] => courses            [term_group] => 0            [term_taxonomy_id] => 3            [taxonomy] => category            [description] =>             [parent] => 1            [count] => 220            [filter] => raw        )    ......)

函数使用示例

$categories = wp_get_object_terms(3522, \'category\');foreach($categories as $category) {echo \'<li><a href=\"\' . get_category_link($category->term_id) . \'\">\' . $category->name . \'</a></li>\';}

扩展阅读

wp_get_object_terms()函数位于:wp-includes/taxonomy.php

相关函数:

  • wp_get_object_terms_args()
  • get_object_terms()
-=||=-收藏赞 (0)
更多主题
v1.0.0
小程序收录免费WordPress主题:XCX主题
¥ 0 关注:22,631
详情
单栏极简文艺WordPress博客主题:Diaspora主题
¥ 0 关注:22,133
详情
简约黑白WordPress个人博客主题:Personal主题
¥ 0 关注:21,864
详情
功能丰富切轻量的WordPress虚拟资源主题:Rizhuti主题
¥ 599 关注:19,927
详情
v1.0.0
一款简约单栏的免费WordPress博客主题:itheme主题
¥ 0 关注:19,841
详情
WordPress版WebStack导航主题:WebStack主题
¥ 0 关注:16,921
详情
回复
暂无评论

不要再留垃圾评论了,主题君整理资源不容易,留几句鼓励的话吧。