The get_post_type_object() WordPress PHP function retrieves a post type object by name.
Usage
$obj = get_post_type_object('post_type_name');
Parameters
- $post_type (string): The name of a registered post type.
More information
See WordPress Developer Resources: get_post_type_object()
Examples
Display Singular Name of a Post Type
// Get the post type object $obj = get_post_type_object('post'); // Display the singular name echo $obj->labels->singular_name;
List All Labels of a Custom Post Type
// Get the post type object $obj = get_post_type_object('certification'); // Display all labels print_r($obj->labels);
Check If a Post Type is Publicly Queryable
// Get the post type object $obj = get_post_type_object('post'); // Check if the post type is publicly queryable if ($obj->publicly_queryable) { echo 'The post type is publicly queryable.'; } else { echo 'The post type is not publicly queryable.'; }
Display the Menu Icon of a Custom Post Type
// Get the post type object $obj = get_post_type_object('certification'); // Display the menu icon echo $obj->menu_icon;
Get the Rewrite Rules of a Post Type
// Get the post type object $obj = get_post_type_object('certification'); // Get the rewrite rules $rewrite = $obj->rewrite; // Display the rewrite rules print_r($rewrite);