函数原型
has_tag( string|int|array $tag = ”, int|WP_Post $post = null ): bool
函数描述
Checks if the current post has any of given tags.
是否弃用
未弃用
函数参数
-
$tag
string|int|array
Optional - The tag name/term_id/slug, or an array of them to check for.
Default:
'' -
$post
int|WP_Post
Optional - Post to check. Defaults to the current post.
Default:
null
函数返回值
bool True if the current post has any of the given tags (or any tag, if no tag specified). False otherwise.
函数位置
File: wp-includes/category-template.php.
函数源码
function has_tag( $tag = '', $post = null ) {
return has_term( $tag, 'post_tag', $post );
}
源码链接
变更日志
| Version | Description |
|---|---|
| 2.7.0 | Can be used outside of the WordPress Loop if $post is provided. |
| 2.6.0 | Introduced. |

