is_post_publicly_viewable

函数
is_post_publicly_viewable ( $post = null )
参数
  • (int|WP_Post|null) $post Optional. Post ID or post object. Defaults to global $post.
    Required:
    Default: null
返回值
  • (bool) Whether the post is publicly viewable.
定义位置
相关方法
is_term_publicly_viewableis_post_type_viewableis_post_status_viewableis_taxonomy_viewableis_post_type_hierarchical
引入
5.7.0
弃用
-

is_post_publicly_viewable: 这个函数检查一个文章是否可以公开查看。它以文章对象或ID为参数,如果文章可以公开查看,则返回true,如果不可以则返回false。

确定一个文章是否可以公开查看。

如果文章的状态和文章的类型都是可查看的,那么文章就被认为是可公开查看的。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function is_post_publicly_viewable( $post = null ) {
$post = get_post( $post );
if ( ! $post ) {
return false;
}
$post_type = get_post_type( $post );
$post_status = get_post_status( $post );
return is_post_type_viewable( $post_type ) && is_post_status_viewable( $post_status );
}
function is_post_publicly_viewable( $post = null ) { $post = get_post( $post ); if ( ! $post ) { return false; } $post_type = get_post_type( $post ); $post_status = get_post_status( $post ); return is_post_type_viewable( $post_type ) && is_post_status_viewable( $post_status ); }
function is_post_publicly_viewable( $post = null ) {
	$post = get_post( $post );

	if ( ! $post ) {
		return false;
	}

	$post_type   = get_post_type( $post );
	$post_status = get_post_status( $post );

	return is_post_type_viewable( $post_type ) && is_post_status_viewable( $post_status );
}

常见问题

FAQs
查看更多 >