WordPress at a glance

has_post_format() WP 1.0

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

Works based on: has_term()
✈ 1 time = 0.001473s = very slow | 50000 times = 63.94s = very slow

No Hooks.

Return

true/false. True if the post has any of the given formats (or any format, if no format specified), false otherwise.

Usage

has_post_format( $format, $post );
$format(string/array)
The format or formats to check.
Default: array()
$post(object/int/null)
The post to check. If not supplied.
Default: current post if used in the loop

Code of has_post_format: wp-includes/post-formats.php VER 5.0.1

<?php
function has_post_format( $format = array(), $post = null ) {
	$prefixed = array();

	if ( $format ) {
		foreach ( (array) $format as $single ) {
			$prefixed[] = 'post-format-' . sanitize_key( $single );
		}
	}

	return has_term( $prefixed, 'post_format', $post );
}

Related Functions

From tag: post format

No comments
    Hello, !     Log In . Register