has_tag()判断当前文章是否有某个指定的标签

目录

描述

Check if the current post has any of the given tags. The given tags are checked against the post's tags' term_ids, names and slugs. Tags given as integers will only be checked against the post's tags' term_ids.

If no tags are given, determines if post has any tags.

Note: This function is mask of:

has_term( $tag, 'post_tag', $post )


Therefore if you are attempting to determine if a post of a custom post type has a particular tag you need to do:

has_term( $tag, 'mycpt_tag', $post )

has_tag() 描述

用法

<?php has_tag$tag$post ); ?>

has_tag() 用法

参数

$tag

(mixed) (可选) The tag name, term_id or slug. Also accepts an array of tag names, term ids and slugs

默认值: None

$post

(object) (可选) Post to check instead of the current post.

默认值: Current post

has_tag() 参数

返回值

(boolean) 

True if the current post has any of the given tags (or any tag, if no tag specified), false otherwise.

has_tag() 返回值

源文件

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

has_tag() 源文件

相关