get_post_type_object()

You are here:

get_post_type_object( string $post_type )

Retrieves a post type object by name.

Description Description

See also See also


Top ↑

Parameters Parameters

$post_type

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


Top ↑

Return Return

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


Top ↑

Source Source

File: wp-includes/post.php

1240
1241
1242
1243
1244
1245
1246
1247
1248
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

Changelog
VersionDescription
4.6.0Object returned is now an instance of WP_Post_Type.
3.0.0Introduced.
Was this article helpful?
Dislike 0
Views: 1

Cart

Log in

Create an Account
Back to Top