Title: is_post_type_viewable
Published: December 9, 2015
Last modified: August 20, 2026

---

# is_post_type_viewable( string|WP_Post_Type $post_type ): bool

## In this article

 * [Description](https://developer.wordpress.org/reference/functions/is_post_type_viewable/?output_format=md#description)
 * [Parameters](https://developer.wordpress.org/reference/functions/is_post_type_viewable/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/functions/is_post_type_viewable/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/functions/is_post_type_viewable/?output_format=md#source)
 * [Hooks](https://developer.wordpress.org/reference/functions/is_post_type_viewable/?output_format=md#hooks)
 * [Related](https://developer.wordpress.org/reference/functions/is_post_type_viewable/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/is_post_type_viewable/?output_format=md#changelog)
 * [User Contributed Notes](https://developer.wordpress.org/reference/functions/is_post_type_viewable/?output_format=md#user-contributed-notes)

Determines whether a post type is considered “viewable”.

## 󠀁[Description](https://developer.wordpress.org/reference/functions/is_post_type_viewable/?output_format=md#description)󠁿

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.

## 󠀁[Parameters](https://developer.wordpress.org/reference/functions/is_post_type_viewable/?output_format=md#parameters)󠁿

 `$post_type`string|[WP_Post_Type](https://developer.wordpress.org/reference/classes/wp_post_type/)
required

Post type name or object.

## 󠀁[Return](https://developer.wordpress.org/reference/functions/is_post_type_viewable/?output_format=md#return)󠁿

 bool Whether the post type should be considered viewable.

## 󠀁[Source](https://developer.wordpress.org/reference/functions/is_post_type_viewable/?output_format=md#source)󠁿

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

    	if ( ! is_object( $post_type ) ) {
    		return false;
    	}

    	$is_viewable = $post_type->publicly_queryable || ( $post_type->_builtin && $post_type->public );

    	/**
    	 * Filters whether a post type is considered "viewable".
    	 *
    	 * The returned filtered value must be a boolean type to ensure
    	 * `is_post_type_viewable()` only returns a boolean. This strictness
    	 * is by design to maintain backwards-compatibility and guard against
    	 * potential type errors in PHP 8.1+. Non-boolean values (even falsey
    	 * and truthy values) will result in the function returning false.
    	 *
    	 * @since 5.9.0
    	 *
    	 * @param bool         $is_viewable Whether the post type is "viewable" (strict type).
    	 * @param WP_Post_Type $post_type   Post type object.
    	 */
    	return true === apply_filters( 'is_post_type_viewable', $is_viewable, $post_type );
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/post.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.1/src/wp-includes/post.php#L2447)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.1/src/wp-includes/post.php#L2447-L2477)

## 󠀁[Hooks](https://developer.wordpress.org/reference/functions/is_post_type_viewable/?output_format=md#hooks)󠁿

 [apply_filters( ‘is_post_type_viewable’, bool $is_viewable, WP_Post_Type $post_type )](https://developer.wordpress.org/reference/hooks/is_post_type_viewable/)

Filters whether a post type is considered “viewable”.

## 󠀁[Related](https://developer.wordpress.org/reference/functions/is_post_type_viewable/?output_format=md#related)󠁿

| Uses | Description | 
| [apply_filters()](https://developer.wordpress.org/reference/functions/apply_filters/)`wp-includes/plugin.php` |

Calls the callback functions that have been added to a filter hook.

  | 
| [get_post_type_object()](https://developer.wordpress.org/reference/functions/get_post_type_object/)`wp-includes/post.php` |

Retrieves a post type object by name.

  |

| Used by | Description | 
| [build_query_vars_from_query_block()](https://developer.wordpress.org/reference/functions/build_query_vars_from_query_block/)`wp-includes/blocks.php` |

Helper function that constructs a [WP_Query](https://developer.wordpress.org/reference/classes/wp_query/) args array from a `Query` block properties.

  | 
| [is_post_publicly_viewable()](https://developer.wordpress.org/reference/functions/is_post_publicly_viewable/)`wp-includes/post.php` |

Determines whether a post is publicly viewable.

  | 
| [WP_REST_Posts_Controller::get_item_schema()](https://developer.wordpress.org/reference/classes/wp_rest_posts_controller/get_item_schema/)`wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php` |

Retrieves the post’s schema, conforming to JSON Schema.

  | 
| [WP_REST_Posts_Controller::prepare_item_for_response()](https://developer.wordpress.org/reference/classes/wp_rest_posts_controller/prepare_item_for_response/)`wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php` |

Prepares a single post output for response.

  | 
| [WP_REST_Posts_Controller::get_item()](https://developer.wordpress.org/reference/classes/wp_rest_posts_controller/get_item/)`wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php` |

Retrieves a single post.

  | 
| [WP_REST_Post_Types_Controller::prepare_item_for_response()](https://developer.wordpress.org/reference/classes/wp_rest_post_types_controller/prepare_item_for_response/)`wp-includes/rest-api/endpoints/class-wp-rest-post-types-controller.php` |

Prepares a post type object for serialization.

  | 
| [WP_Post_Type::add_rewrite_rules()](https://developer.wordpress.org/reference/classes/wp_post_type/add_rewrite_rules/)`wp-includes/class-wp-post-type.php` |

Adds the necessary rewrite rules for the post type.

  | 
| [get_preview_post_link()](https://developer.wordpress.org/reference/functions/get_preview_post_link/)`wp-includes/link-template.php` |

Retrieves the URL used for the post preview.

  | 
| [WP_Posts_List_Table::handle_row_actions()](https://developer.wordpress.org/reference/classes/wp_posts_list_table/handle_row_actions/)`wp-admin/includes/class-wp-posts-list-table.php` |

Generates and displays row action links.

  | 
| [post_submit_meta_box()](https://developer.wordpress.org/reference/functions/post_submit_meta_box/)`wp-admin/includes/meta-boxes.php` |

Displays post submit form fields.

  | 
| [WP_Posts_List_Table::inline_edit()](https://developer.wordpress.org/reference/classes/wp_posts_list_table/inline_edit/)`wp-admin/includes/class-wp-posts-list-table.php` |

Outputs the hidden row displayed when inline editing

  | 
| [wp_get_archives()](https://developer.wordpress.org/reference/functions/wp_get_archives/)`wp-includes/general-template.php` |

Displays archive links based on type and format.

  | 
| [WP::parse_request()](https://developer.wordpress.org/reference/classes/wp/parse_request/)`wp-includes/class-wp.php` |

Parses the request to find the correct WordPress query.

  | 
| [get_attachment_link()](https://developer.wordpress.org/reference/functions/get_attachment_link/)`wp-includes/link-template.php` |

Retrieves the permalink for an attachment.

  |

[Show 9 more](https://developer.wordpress.org/reference/functions/is_post_type_viewable/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/functions/is_post_type_viewable/?output_format=md#)

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/is_post_type_viewable/?output_format=md#changelog)󠁿

| Version | Description | 
| [5.9.0](https://developer.wordpress.org/reference/since/5.9.0/) | Added `is_post_type_viewable` hook to filter the result. | 
| [4.6.0](https://developer.wordpress.org/reference/since/4.6.0/) | Converted the `$post_type` parameter to accept a `WP_Post_Type` object. | 
| [4.5.0](https://developer.wordpress.org/reference/since/4.5.0/) | Added the ability to pass a post type name in addition to object. | 
| [4.4.0](https://developer.wordpress.org/reference/since/4.4.0/) | Introduced. |

## 󠀁[User Contributed Notes](https://developer.wordpress.org/reference/functions/is_post_type_viewable/?output_format=md#user-contributed-notes)󠁿

 1.  [Skip to note 2 content](https://developer.wordpress.org/reference/functions/is_post_type_viewable/?output_format=md#comment-content-6345)
 2.   [Munaf Vichhi](https://profiles.wordpress.org/vichhimunaf/)  [  4 years ago  ](https://developer.wordpress.org/reference/functions/is_post_type_viewable/#comment-6345)
 3. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fis_post_type_viewable%2F%23comment-6345)
    Vote results for this note: 0[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fis_post_type_viewable%2F%23comment-6345)
 4. Using this hook you can hide single custom posts URL.
 5.     ```php
        add_filter( 'is_post_type_viewable', function ( $is_viewable, $post_type ) {
            if ( false == $is_viewable || 'sample_post_type' === $post_type->name ) {
                return false;
            }
    
            return true;
        }, 10, 2 );
        ```
    
 6.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fis_post_type_viewable%2F%3Freplytocom%3D6345%23feedback-editor-6345)

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fis_post_type_viewable%2F)
before being able to contribute a note or feedback.