has_category

Check if the current post has any of given category.

Description

has_category( (string) $category = '', (null) $post = null ); 

Parameters (2)

0. $category — Optional. (string) => ''
The category name/term_id/slug or array of them to check for.
1. $post — Optional. (null) => null
Post to check instead of the current post.

Usage

  1. if ( !function_exists( 'has_category' ) ) { 
  2. require_once ABSPATH . WPINC . '/category-template.php'; 
  3.  
  4. // Optional. The category name/term_id/slug or array of them to check for. 
  5. $category = ''; 
  6.  
  7. // Optional. Post to check instead of the current post. 
  8. $post = null; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = has_category($category, $post); 
  12.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/category-template.php  
  1. function has_category( $category = '', $post = null ) { 
  2. return has_term( $category, 'category', $post );