确定查询是针对任何帖子类型(帖子,附件,页面,自定义帖子类型)的现有单个帖子。
原型
is_singular( string|array $post_types = '' )
描述
如果指定了$ post_types参数,则此函数将另外检查查询是否针对指定的Posts Types之一。
参考:
- is_page()
- is_single()
参数
$post_types
(string|array)
(Optional)
帖子类型或帖子类型数组。
返回值
(bool)
查询是否针对任何给定帖子类型的现有单个帖子。
源文件
路径:wp-includes/query.php
<?php
...
function is_singular( $post_types = '' ) {
global $wp_query;
if ( ! isset( $wp_query ) ) {
_doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1.0' );
return false;
}
return $wp_query->is_singular( $post_types );
}
...
?>
其他
英文文档:https://developer.wordpress.org/reference/functions/is_singular/