Checks if the current post has any of given category.
Description
The given categories are checked against the post's categories' term_ids, names and slugs.Categories given as integers will only be checked against the post's categories' term_ids. If no categories are given, determines if post has any categories.
Parameters
$categorystring|int|arrayoptional
The category name/term_id/slug, or an array of them to check for. Default empty.Default: ''
$postint|WP_Postoptional
Post to check. Defaults to the current post.Default: null
Return
bool
True if the current post has any of the given categories (or any category, if no category specified). False otherwise.
Uses · 1
has_term()Checks if the current post has any of given terms.
Used by · 3
in_category()Checks if the current post is within any of the given categories.
Signature, return type and hooks compared across 5 parsed releases.
7.0.4
Parameter $post retyped from int|WP_Post to int|WP_Post|null.verified against source
3.1.0
Introduced.from the docblock
About this page
Parsed data
Generated from the wordpress-develop 6.9.7 tag, from src/wp-includes/category-template.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.