has_post_format

The timeline below displays how wordpress function has_post_format has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.2

/**
 * Check if a post has any of the given formats, or any format.
 *
 * @since 3.1.0
 *
 * @param string|string[]  $format Optional. The format or formats to check. Default empty array.
 * @param WP_Post|int|null $post   Optional. The post to check. Defaults to the current post in the loop.
 * @return bool True if the post has any of the given formats (or any format, if no format specified),
 *              false otherwise.
 */
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);
}

WordPress Version: 5.7

/**
 * Check if a post has any of the given formats, or any format.
 *
 * @since 3.1.0
 *
 * @param string|string[]  $format Optional. The format or formats to check.
 * @param WP_Post|int|null $post   Optional. The post to check. Defaults to the current post in the loop.
 * @return bool True if the post has any of the given formats (or any format, if no format specified),
 *              false otherwise.
 */
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);
}

WordPress Version: 5.5

/**
 * Check if a post has any of the given formats, or any format.
 *
 * @since 3.1.0
 *
 * @param string|array     $format Optional. The format or formats to check.
 * @param WP_Post|int|null $post   Optional. The post to check. Defaults to the current post in the loop.
 * @return bool True if the post has any of the given formats (or any format, if no format specified),
 *              false otherwise.
 */
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);
}

WordPress Version: 5.4

/**
 * Check if a post has any of the given formats, or any format.
 *
 * @since 3.1.0
 *
 * @param string|array     $format Optional. The format or formats to check.
 * @param WP_Post|int|null $post   Optional. The post to check. If not supplied, defaults to the current post if used in the loop.
 * @return bool True if the post has any of the given formats (or any format, if no format specified), false otherwise.
 */
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);
}

WordPress Version: 4.3

/**
 * Check if a post has any of the given formats, or any format.
 *
 * @since 3.1.0
 *
 * @param string|array    $format Optional. The format or formats to check.
 * @param object|int|null $post   Optional. The post to check. If not supplied, defaults to the current post if used in the loop.
 * @return bool True if the post has any of the given formats (or any format, if no format specified), false otherwise.
 */
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);
}

WordPress Version: 4.1

/**
 * Check if a post has any of the given formats, or any format.
 *
 * @since 3.1.0
 *
 * @param string|array $format Optional. The format or formats to check.
 * @param object|int $post Optional. The post to check. If not supplied, defaults to the current post if used in the loop.
 * @return bool True if the post has any of the given formats (or any format, if no format specified), false otherwise.
 */
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);
}

WordPress Version: 3.8

/**
 * Check if a post has any of the given formats, or any format.
 *
 * @since 3.1.0
 *
 * @uses has_term()
 *
 * @param string|array $format Optional. The format or formats to check.
 * @param object|int $post Optional. The post to check. If not supplied, defaults to the current post if used in the loop.
 * @return bool True if the post has any of the given formats (or any format, if no format specified), false otherwise.
 */
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);
}

WordPress Version: 3.7

/**
 * Check if a post has a particular format
 *
 * @since 3.1.0
 *
 * @uses has_term()
 *
 * @param string|array $format The format or formats to check.
 * @param object|int   $post   The post to check. If not supplied, defaults to the current post if used in the loop.
 * @return bool True if the post has the format, false otherwise.
 */
function has_post_format($format, $post = null)
{
    if (!is_array($format)) {
        $format = array($format);
    }
    $prefixed = array();
    foreach ($format as $single) {
        $prefixed[] = 'post-format-' . sanitize_key($single);
    }
    return has_term($prefixed, 'post_format', $post);
}