get_post_type_object

函数


get_post_type_object ( $post_type )
参数
  • (string)
    $post_type
    The name of a registered post type.
    Required:
返回值
  • (WP_Post_Type|null) WP_Post_Type object if it exists, null otherwise.
相关
  • register_post_type()
定义位置
  • wp-includes/post.php
    , line 1488
引入
3.0.0
弃用

按名称检索一个文章类型对象。

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 ];
}