wp_get_post_terms

函数
wp_get_post_terms ( $post_id = 0, $taxonomy = 'post_tag', $args = array() )
参数
  • (int) $post_id Optional. The Post ID. Does not default to the ID of the global $post. Default 0.
    Required:
  • (string|string[]) $taxonomy Optional. The taxonomy slug or array of slugs for which to retrieve terms. Default 'post_tag'.
    Required:
    Default: 'post_tag'
  • (array) $args { Optional. Term query parameters. See WP_Term_Query::__construct() for supported arguments. @type string $fields Term fields to retrieve. Default 'all'. }
    Required:
    Default: array()
返回值
  • (array|WP_Error) Array of WP_Term objects on success or empty array if no terms were found. WP_Error object if `$taxonomy` doesn't exist.
定义位置
相关方法
wp_set_post_termswp_get_split_termswp_get_post_catswp_get_post_tagswp_get_object_terms
引入
2.8.0
弃用
-

wp_get_post_terms: 这个函数用于检索与特定文章相关的术语(类别、标签等)。它把文章的ID和分类法作为参数,并返回一个术语对象的数组,每个对象都包含有关术语的信息。

检索一个文章的术语。

function wp_get_post_terms( $post_id = 0, $taxonomy = 'post_tag', $args = array() ) {
	$post_id = (int) $post_id;

	$defaults = array( 'fields' => 'all' );
	$args     = wp_parse_args( $args, $defaults );

	$tags = wp_get_object_terms( $post_id, $taxonomy, $args );

	return $tags;
}

常见问题

FAQs
查看更多 >