WordPress at a glance

is_post_type_viewable() WP 1.0

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.

  • 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.
✈ 1 time = 0.000015s = very fast | 50000 times = 0.04s = speed of light PHP 7.0.5, WP 4.4.2

No Hooks.

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.

Code of is_post_type_viewable: wp-includes/post.php VER 4.9.8

<?php
function is_post_type_viewable( $post_type ) {
	if ( is_scalar( $post_type ) ) {
		$post_type = get_post_type_object( $post_type );
		if ( ! $post_type ) {
			return false;
		}
	}

	return $post_type->publicly_queryable || ( $post_type->_builtin && $post_type->public );
}

Related Functions

From tag: Custom post type (post_type)

More from category: Custom Types

No comments
    Hello, !     Log In . Register