检查帖子是否具有任何给定格式或任何格式。
原型
has_post_format( string|array $format = array(), object|int|null $post = null )
参数
$format
(string|array)
(Optional)
要检查的格式。
$post
(object|int|null)
(Optional)
要检查的帖子。如果未提供,则在循环中使用时默认为当前帖子。
返回值
(bool)
如果帖子具有任何给定格式(或任何格式,如果未指定格式),则为True,否则为false。
源文件
路径:wp-includes/post-formats.php
<?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 );
}
...
?>
其他
英文文档:https://developer.wordpress.org/reference/functions/has_post_format/