get_post_type_object() WordPress Function

The get_post_type_object() function is used to retrieve information about a post type. This function can be used to check if a post type exists, and if so, retrieve information about it. This function can also be used to get a list of all registered post types.

get_post_type_object( string $post_type ) #

Retrieves a post type object by name.


Description

Top ↑

See also


Top ↑

Parameters

$post_type

(string)(Required)The name of a registered post type.


Top ↑

Return

(WP_Post_Type|null) WP_Post_Type object if it exists, null otherwise.


Top ↑

Source

File: wp-includes/post.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 ];
}


Top ↑

Changelog

Changelog
VersionDescription
4.6.0Object returned is now an instance of WP_Post_Type.
3.0.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.

Show More
Show More