函数原型
has_category( string|int|array $category = ”, int|WP_Post $post = null ): bool
函数描述
Checks if the current post has any of given category.
是否弃用
未弃用
函数参数
-
$category
string|int|array
Optional - The category 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 categories (or any category, if no category specified). False otherwise.
函数位置
File: wp-includes/category-template.php.
函数源码
function has_category( $category = '', $post = null ) {
return has_term( $category, 'category', $post );
}
源码链接
变更日志
| Version | Description |
|---|---|
| 3.1.0 | Introduced. |

