is_post_type_viewable()
Determines whether a post type is considered "viewable".
For built-in post types such as posts and pages, the 'public' value will be evaluated. For all others, the 'publicly_queryable' value will be used.
1 time — 0.000015 sec (very fast) | 50000 times — 0.04 sec (speed of light) | PHP 7.0.5, WP 4.4.2
Hooks from the function
Return
true|false
. Whether the post type should be considered viewable.
Usage
is_post_type_viewable( $post_type );
- $post_type(string|WP_Post_Type) (required)
- Post type name or object.
Examples
#1 Check if the post type is viewable
Suppose there is a post type myposts
and we need to check whether ordinary visitors can see this post type.
$obj = get_post_type_object( 'myposts' ); if( is_post_type_viewable( $obj ) ){ echo 'viewable post type'; } else { echo 'internal post type'; }
Changelog
Since 4.4.0 | Introduced. |
Since 4.5.0 | Added the ability to pass a post type name in addition to object. |
Since 4.6.0 | Converted the $post_type parameter to accept a WP_Post_Type object. |
Since 5.9.0 | Added is_post_type_viewable to filter the result. |