WordPress at a glance

get_post_type_object() WP 1.0

Retrieves a post type object by name.

Notes:

  • Global. Array. $wp_post_types List of post types.
  • See: register_post_type()
  • Since 4.6.0 Object returned is now an instance of WP_Post_Type.
✈ 1 time = 0.000068s = very fast | 50000 times = 2.36s = fast PHP 7.0.5, WP 4.5.2

No Hooks.

Return

WP_Post_Type/null. WP_Post_Type object if it exists, null otherwise.

Usage

get_post_type_object( $post_type );
$post_type(string) (required)
The name of a registered post type.

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

<?php
function get_post_type_object( $post_type ) {
	global $wp_post_types;

	if ( ! is_scalar( $post_type ) || empty( $wp_post_types[ $post_type ] ) ) {
		return null;
	}

	return $wp_post_types[ $post_type ];
}

Related Functions

From tag: Custom post type (post_type)

More from category: Custom Types

No comments
    Hello, !     Log In . Register