WordPress函数wp_get_post_categories根据文章的ID获取该文章所在分类,如果文章分配了多个分类,则返回所有分类的ID。
wp_get_post_categories( int $post_id, array $args = array() )
函数参数
$post_id
整数
文章的ID
$args
数组
分类查询参数,可以参考get_categories()函数的参数说明。
函数返回值
返回一个数组,包含该文章所在的所有分类ID,例如:
Array
(
[0] => 1
[1] => 35
[2] => 3
)
函数使用示例
$post_categories = wp_get_post_categories($post_id);
foreach($post_categories as $c){
$cat = get_category($c);
echo 'term_id)) . '">' . $cat->name . ' ';
}
扩展阅读
wp_get_post_categories()函数位于:wp-includes/post.php
相关函数:
- wp_get_object_terms()
- wp_get_post_terms()
- wp_get_post_cats()
- wp_get_post_tags()
- wp_set_post_categories()
- get_category()
原创文章,作者:,如若转载,请注明出处:https://ce.771633.xyz/1906.html