Filter hook 'is_post_type_viewable'

in WP Core File wp-includes/post.php at line 2403

View Source

is_post_type_viewable

Filter Hook
Description
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.

Hook Information

File Location wp-includes/post.php View on GitHub
Hook Type Filter
Line Number 2403

Hook Parameters

Type Name Description
bool $is_viewable Whether the post type is "viewable" (strict type).
WP_Post_Type $post_type Post type object.

Usage Examples

Basic Usage
<?php
// Hook into is_post_type_viewable
add_filter('is_post_type_viewable', 'my_custom_filter', 10, 2);

function my_custom_filter($is_viewable, $post_type) {
    // Your custom filtering logic here
    return $is_viewable;
}

Source Code Context

wp-includes/post.php:2403 - How this hook is used in WordPress core
<?php
2398  	 * @since 5.9.0
2399  	 *
2400  	 * @param bool         $is_viewable Whether the post type is "viewable" (strict type).
2401  	 * @param WP_Post_Type $post_type   Post type object.
2402  	 */
2403  	return true === apply_filters( 'is_post_type_viewable', $is_viewable, $post_type );
2404  }
2405  
2406  /**
2407   * Determines whether a post status is considered "viewable".
2408   *

PHP Documentation

<?php
/**
	 * 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.
	 */
Quick Info
  • Hook Type: Filter
  • Parameters: 2
  • File: wp-includes/post.php
Related Hooks

Related hooks will be displayed here in future updates.