WordPress函数wp_get_post_tags()获取文章的标签Tags信息

描述:

获取文章的标签Tags信息

用法:

<?php wp_get_post_tags( $post_id, $args ) ?>

参数:

$post_id

(integer) (可选) The Post ID.

默认值: 0

$args

(array) (可选) Overwrite the defaults. See wp_get_object_terms() for a list of valid options that can be passed.

默认值: array

示例:

$t = wp_get_post_tags($post->ID);
print_r($t);

返回值:

Array
(
   [0] => stdClass Object
       (
           [term_id] => 4
           [name] => tag2
           [slug] => tag2
           [term_group] => 0
           [term_taxonomy_id] => 4
           [taxonomy] => post_tag
           [description] => 
           [parent] => 0
           [count] => 7
       )

   [1] => stdClass Object
       (
           [term_id] => 7
           [name] => tag5
           [slug] => tag5
           [term_group] => 0
           [term_taxonomy_id] => 7
           [taxonomy] => post_tag
           [description] => 
           [parent] => 0
           [count] => 6
       )

   [2] => stdClass Object
       (
           [term_id] => 16
           [name] => tag6
           [slug] => tag6
           [term_group] => 0
           [term_taxonomy_id] => 16
           [taxonomy] => post_tag
           [description] => 
           [parent] => 0
           [count] => 2
       )

)

源文件:

/**
 * Retrieve the tags for a post.
 *
 * There is only one default for this function, called 'fields' and by default
 * is set to 'all'. There are other defaults that can be overridden in
 * {@link wp_get_object_terms()}.
 *
 * @since 2.3.0
 *
 * @param int   $post_id Optional. The Post ID. Does not default to the ID of the
 *                       global $post. Defualt 0.
 * @param array $args Optional. Overwrite the defaults
 * @return array List of post tags.
 */
function wp_get_post_tags( $post_id = 0, $args = array() ) {
	return wp_get_post_terms( $post_id, 'post_tag', $args);
}