On this page
is_post_publicly_viewable( int|WP_Post|null $post = null ): bool
Determines whether a post is publicly viewable.
Description
Posts are considered publicly viewable if both the post status and post type are viewable.
Parameters
$postint|WP_Post|null Optional-
Post ID or post object. Defaults to global $post.
Default:
null
Return
bool Whether the post is publicly viewable.
Source
File: wp-includes/post.php. View all references
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 );
}
Related
Uses
| Uses | Description |
|---|---|
| is_post_status_viewable() wp-includes/post.php | Determines whether a post status is considered “viewable”. |
| is_post_type_viewable() wp-includes/post.php | Determines whether a post type is considered “viewable”. |
| get_post_type() wp-includes/post.php | Retrieves the post type of the current post or of a given post. |
| get_post_status() wp-includes/post.php | Retrieves the post status based on the post ID. |
| get_post() wp-includes/post.php | Retrieves post data given a post ID or post object. |
Used By
| Used By | Description |
|---|---|
| WP_REST_Terms_Controller::check_read_terms_permission_for_post() wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php | Checks if the terms for a post can be read. |
| get_oembed_response_data() wp-includes/embed.php | Retrieves the oEmbed response data for a given post. |
| redirect_canonical() wp-includes/canonical.php | Redirects incoming links to the proper URL based on the site url. |
Changelog
| Version | Description |
|---|---|
| 5.7.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/is_post_publicly_viewable