get_tag()获取文章标签

功能:

get_tag()函数功能是用来返回指定文章ID或者对象的标签。

<?php get_tag( $tag, $output, $filter ) ?>

参数:

$tag
(integer|object) (必选)
默认: 无
$output
(string) (可选) 常量 OBJECT, ARRAY_A, or ARRAY_N
默认: OBJECT
$filter
(string) (可选) 过滤
默认: ‘raw’

返回值:

(object|array)
返回的对象是基于$output的值

所在位置:

get_tag() 函数包含在 wp-includes/category.php 中。

源码:

/**
 * Retrieve post tag by tag ID or tag object.
 *
 * If you pass the $tag parameter an object, which is assumed to be the tag row
 * object retrieved the database. It will cache the tag data.
 *
 * If you pass $tag an integer of the tag ID, then that tag will
 * be retrieved from the database, if it isn't already cached, and pass it back.
 *
 * If you look at get_term(), then both types will be passed through several
 * filters and finally sanitized based on the $filter parameter value.
 *
 * @since 2.3.0
 *
 * @param int|WP_Term|object $tag    A tag ID or object.
 * @param string             $output Optional. The required return type. One of OBJECT, ARRAY_A, or ARRAY_N, which correspond to
 *                                   a WP_Term object, an associative array, or a numeric array, respectively. Default OBJECT.
 * @param string             $filter Optional. Default is raw or no WordPress defined filter will applied.
 * @return WP_Term|array|WP_Error|null Tag data in type defined by $output parameter. WP_Error if $tag is empty, null if it does not exist.
 */
function get_tag( $tag, $output = OBJECT, $filter = 'raw' ) {
	return get_term( $tag, 'post_tag', $output, $filter );
}

示例:

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

相关函数:

get_tags()

(完)

版权声明WordPress头条正在使用WordPress文章版权插件
如未注明,均为原创,转载需注明出处
本文链接地址:http://www.wptoutiao.com/functions/156.html

文章标签的相关文章

还可以分享文章给好友:

发表评论

电子邮件地址不会被公开。 必填项已用*标注