get_tag()通过标签id或对象获取所有标签信息

目录

描述

译文

按标签(tag)编号或标签对象检索文章标签。

传递一个检索数据库的标签行对象给$tag参数,参数可缓存标签数据。

传递一个标签编号整数给$tag参数,若标签未被缓存,则标签将从数据库中被检索并回传。

查看get_term()后标签编号和对象都会被若干过滤器传递,并最终根据$filter参数值被审查。

原文

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.

get_tag() 描述

用法

<?php &get_tag$tag$output$filter ?>

get_tag() 用法

参数

$tag

(integer|object) (必填)

默认值: None

$output

(string) (可选) Constant OBJECT, ARRAY_A, or ARRAY_N

默认值: OBJECT

$filter

(string) (可选) Default is raw or no WordPress defined filter will applied.

默认值: 'raw'

get_tag() 参数

返回值

(object|array) 

Return type based on $output value.

get_tag() 返回值

注意

  • 使用到: get_term() Used to get the tag data from the taxonomy.

get_tag() 注意

历史

添加于 版本: 2.3.0

get_tag() 历史

源文件

&get_tag() 函数的代码位于 wp-includes/category.php.

/* ----------------------------------
 * wordpress之魂 © http://wphun.com
 * ---------------------------------- */
/**
 * 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|object $tag
 * @param string $output Optional. Constant OBJECT, ARRAY_A, or ARRAY_N
 * @param string $filter Optional. Default is raw or no WordPress defined filter will applied.
 * @return object|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 );
}

/* Cache */

get_tag() 源文件