检查当前帖子是否包含任何给定标签。
原型
has_tag( string|int|array $tag = '', int|object $post = null )
描述
根据帖子的标签’term_ids,名称和slugs检查给定的标签。以整数形式给出的标签只会根据帖子的标签’term_ids进行检查。如果没有给出标签,则确定post是否有任何标签。
参数
$tag
(string|int|array)
(Optional)
标签名称/ term_id / slug或要检查的数组。
$post
(int|object)
(Optional)
发布以检查而不是当前的帖子。 (自2.7.0起)
返回值
(bool)
如果当前帖子具有任何给定标签(或任何标签,如果未指定标签),则为True。
源文件
路径:wp-includes/category-template.php
<?php
...
function has_tag( $tag = '', $post = null ) {
return has_term( $tag, 'post_tag', $post );
}
...
?>
其他
英文文档:https://developer.wordpress.org/reference/functions/has_tag/