函数原型
get_post_type_object( string $post_type ): WP_Post_Type|null
函数描述
Retrieves a post type object by name.
是否弃用
未弃用
函数参数
-
$post_type
string
Required - The name of a registered post type.
函数返回值
WP_Post_Type|null WP_Post_Type object if it exists, null otherwise.
函数位置
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 ];
}
源码链接
变更日志
| Version | Description |
|---|---|
| 4.6.0 | Object returned is now an instance of WP_Post_Type. |
| 3.0.0 | Introduced. |

