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.
Parameters
- $post
-
(int|WP_Post|null) (Optional) Post ID or post object. Defaults to global $post.
Default value: null
Return
(bool) Whether the post is publicly viewable.
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 ); }
Changelog
Version | Description |
---|---|
5.7.0 | Introduced. |
© 2003–2021 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/is_post_publicly_viewable