Title: has_category
Published: April 25, 2014
Last modified: February 24, 2026

---

# has_category( string|int|array $category, int|WP_Post $post = null ): bool

## In this article

 * [Description](https://developer.wordpress.org/reference/functions/has_category/?output_format=md#description)
 * [Parameters](https://developer.wordpress.org/reference/functions/has_category/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/functions/has_category/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/functions/has_category/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/functions/has_category/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/has_category/?output_format=md#changelog)
 * [User Contributed Notes](https://developer.wordpress.org/reference/functions/has_category/?output_format=md#user-contributed-notes)

[ Back to top](https://developer.wordpress.org/reference/functions/has_category/?output_format=md#wp--skip-link--target)

Checks if the current post has any of given category.

## 󠀁[Description](https://developer.wordpress.org/reference/functions/has_category/?output_format=md#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](https://developer.wordpress.org/reference/functions/has_category/?output_format=md#parameters)󠁿

 `$category`string|int|arrayoptional

The category name/term_id/slug, or an array of them to check for. Default empty.

`$post`int|[WP_Post](https://developer.wordpress.org/reference/classes/wp_post/)
optional

Post to check. Defaults to the current post.

Default:`null`

## 󠀁[Return](https://developer.wordpress.org/reference/functions/has_category/?output_format=md#return)󠁿

 bool True if the current post has any of the given categories (or any category,
if no category specified). False otherwise.

## 󠀁[Source](https://developer.wordpress.org/reference/functions/has_category/?output_format=md#source)󠁿

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

[View all references](https://developer.wordpress.org/reference/files/wp-includes/category-template.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-includes/category-template.php#L1494)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-includes/category-template.php#L1494-L1496)

## 󠀁[Related](https://developer.wordpress.org/reference/functions/has_category/?output_format=md#related)󠁿

| Uses | Description | 
| [has_term()](https://developer.wordpress.org/reference/functions/has_term/)`wp-includes/category-template.php` |

Checks if the current post has any of given terms.

  |

| Used by | Description | 
| [in_category()](https://developer.wordpress.org/reference/functions/in_category/)`wp-includes/category-template.php` |

Checks if the current post is within any of the given categories.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/has_category/?output_format=md#changelog)󠁿

| Version | Description | 
| [3.1.0](https://developer.wordpress.org/reference/since/3.1.0/) | Introduced. |

## 󠀁[User Contributed Notes](https://developer.wordpress.org/reference/functions/has_category/?output_format=md#user-contributed-notes)󠁿

 1.   [Skip to note 2 content](https://developer.wordpress.org/reference/functions/has_category/?output_format=md#comment-content-1981)
 2.    [Mithun Raval](https://profiles.wordpress.org/mitraval192/)  [  9 years ago  ](https://developer.wordpress.org/reference/functions/has_category/#comment-1981)
 3.  [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fhas_category%2F%23comment-1981)
     Vote results for this note: 1[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fhas_category%2F%23comment-1981)
 4.  The current post has set the categories that time this function will return true.
     
     if you want to check specific category is set for this post.
 5.      ```php
         if (has_category('Category_name',$post->ID))
         ```
     
 6.  If you want to use it in The Loop, you don’t need to specify the ID.
 7.      ```php
         if (has_category('Category_name'))
         ```
     
 8.  Check multiple category:
 9.      ```php
         if(has_category(array('category_name_1', 'category_name_2')))
         ```
     
 10.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fhas_category%2F%3Freplytocom%3D1981%23feedback-editor-1981)

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fhas_category%2F)
before being able to contribute a note or feedback.