WordPress at a glance

has_category() WP 1.0

Check if the current post has any of given category.

Is the basis for: in_category()
Works based on: has_term()
✈ 1 time = 0.003414s = very slow | 50000 times = 0.84s = very fast PHP 7.1.5, WP 4.8.1

No Hooks.


true/false. True if the current post has any of the given categories (or any category, if no category specified).


has_category( $category, $post );
The category name/term_id/slug or array of them to check for.
Default: ''
Post to check instead of the current post.
Default: null

Code of has_category: wp-includes/category-template.php VER 4.9.8

function has_category( $category = '', $post = null ) {
	return has_term( $category, 'category', $post );

Related Functions

From tag: Conditional tags (all)

More from category: For posts

No comments
    Hello, !     Log In . Register