is_post_publicly_viewable() WordPress Function

The is_post_publicly_viewable() function is used to check if a post is publicly viewable. This function returns true if the post is publicly viewable, and false if the post is not publicly viewable.

is_post_publicly_viewable( int|WP_Post|null $post = null ) #

Determine whether a post is publicly viewable.


Description

Posts are considered publicly viewable if both the post status and post type are viewable.


Top ↑

Parameters

$post

(int|WP_Post|null)(Optional) Post ID or post object. Defaults to global $post.

Default value: null


Top ↑

Return

(bool) Whether the post is publicly viewable.


Top ↑

Source

File: wp-includes/post.php

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 );
}


Top ↑

Changelog

Changelog
VersionDescription
5.7.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.

Show More
Show More