wp_get_post_terms()获取文章的分类法数组

目录

描述

Retrieve the terms for a post.

There is only one default for this function, called 'fields' and by default is set to 'all'. Other values can be 'names' or 'ids'. There are other defaults that can be overridden in wp_get_object_terms().

wp_get_post_terms() 描述

用法

<?php $terms wp_get_post_terms$post_id$taxonomy$args ); ?>

wp_get_post_terms() 用法

参数

$post_id

(integer) (可选) The Post ID

默认值: 0

$taxonomy

(string|array) (可选) The taxonomy for which to retrieve terms. Defaults to post_tag.

默认值: 'post_tag'

$args

(array) (可选) Overwrite the defaults

默认值: array

Default Arguments

$args = array('orderby' => 'name', 'order' => 'ASC', 'fields' => 'all');

wp_get_post_terms() 参数

返回值

(array|WP_Error) 

List of post tags. WP_Error if $taxonomy does not exist. See is_wp_error() for more information.

Variables in Returned Object

term_id (int) 

the id of the term itself

name (string) 

the term name

slug (string) 

a slug generated from the term name

term_group (int) 

the term_id of the parent term (also stored as 'parent')

term_taxonomy_id (int) 

the id of the taxonomy that the term belongs to

taxonomy (string) 

the name of the taxonomy that the term belongs to

description (string) 

the taxonomy description

parent (int) 

the term_id of the parent term (also stored as 'term_group')

count (int) 

the number of uses of this term

wp_get_post_terms() 返回值

示例

wp_get_post_terms() 示例

注意

wp_get_post_terms() 注意

历史

添加于 版本: 2.8.0

wp_get_post_terms() 历史

源文件

wp_get_post_terms() 函数的代码位于 wp-includes/post.php.

wp_get_post_terms() 源文件

相关