has_post_format()

最后更新于:2021-11-27 05:06:17

has_post_format( string|string[]$format=array(), GC_Post|int|null$post=null)

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

参数

$format

(string|string[]) (Optional) The format or formats to check.

Default value: array()

$post

(GC_Post|int|null) (Optional) The post to check. Defaults to the current post in the loop.

Default value: null

响应

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

源文件

文件: gc-includes/post-formats.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 );
}