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
檢視更多 >