WordPress: Check If a Post Belongs to a Category

WordPress provides an function to help developer check whether a post has a specific category.

has_category( string|int|array $category = '', int|object $post = null )

has_category() returns true if the referenced post has any of the given categories.


  • $category: it can be category id, slug, name or an array of them. This is the category you want to check if the post belongs to.
  • $post: post object or post id you want to check. If this function is put in The Loop, you don’t need to specify the ID.
  echo 'This is a Development post';

Leave a Comment

Your email address will not be published.

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.