tag_exists()
云策文档标注
概述
tag_exists() 函数用于检查指定名称的文章标签是否存在。它基于 term_exists() 函数实现,专门针对 post_tag 分类法。
关键要点
- 参数 $tag_name 是必需的,可以是整数或字符串类型。
- 返回值根据情况不同:标签不存在时返回 null;存在时返回包含标签 ID 和分类法 ID 的数组;如果传入 term ID 0,则返回 0。
- 该函数是 term_exists() 的封装,简化了对文章标签的检查操作。
代码示例
function tag_exists( $tag_name ) {
return term_exists( $tag_name, 'post_tag' );
}注意事项
- 该函数自 WordPress 2.3.0 版本引入。
- 相关函数 term_exists() 可用于更通用的分类法术语检查。
原文内容
Checks whether a post tag with a given name exists.
Parameters
$tag_nameint|stringrequired
Source
function tag_exists( $tag_name ) {
return term_exists( $tag_name, 'post_tag' );
}
Changelog
| Version | Description |
|---|---|
| 2.3.0 | Introduced. |