has_post_format

Check if a post has any of the given formats, or any format.

Description

has_post_format( (array) $format = array(), (null) $post = null ); 

Parameters (2)

0. $format — Optional. (array) => array()
The format or formats to check.
1. $post — Optional. (null) => null
The post to check. If not supplied, defaults to the current post if used in the loop.

Usage

  1. if ( !function_exists( 'has_post_format' ) ) { 
  2. require_once ABSPATH . WPINC . '/post-formats.php'; 
  3.  
  4. // Optional. The format or formats to check. 
  5. $format = array(); 
  6.  
  7. // Optional. The post to check. If not supplied, defaults to the current post if used in the loop. 
  8. $post = null; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = has_post_format($format, $post); 
  12.  

Defined (1)

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

/wp-includes/post-formats.php  
  1. function has_post_format( $format = array(), $post = null ) { 
  2. $prefixed = array(); 
  3.  
  4. if ( $format ) { 
  5. foreach ( (array) $format as $single ) { 
  6. $prefixed[] = 'post-format-' . sanitize_key( $single ); 
  7.  
  8. return has_term( $prefixed, 'post_format', $post );