函数原型
in_category( int|string|int[]|string[] $category, int|WP_Post $post = null ): bool
函数描述
Checks if the current post is within any of the given categories.
是否弃用
未弃用
函数参数
-
$category
int|string|int[]|string[]
Required - Category ID, name, slug, or array of such to check against.
-
$post
int|WP_Post
Optional - Post to check. Defaults to the current post.
Default:
null
函数返回值
bool True if the current post is in any of the given categories.
函数位置
File: wp-includes/category-template.php.
函数源码
function in_category( $category, $post = null ) {
if ( empty( $category ) ) {
return false;
}
return has_category( $category, $post );
}
源码链接
变更日志
| Version | Description |
|---|---|
| 2.7.0 | The $post parameter was added. |
| 1.2.0 | Introduced. |

