WordPress函数get_post_type_object()通过名称获取自定义文章类型的信息

描述:

通过文章类型名词获取该类型的信息

用法:

<?php get_post_type_object( $post_type ); ?>

参数:

$post_type

(string) (必填) 自定义文章类型的name

默认值: None

示例:

$obj = get_post_type_object( 'post' );
echo $obj->labels->singular_name;

源文件:

/**
 * Retrieve a post type object by name.
 *
 * @since 3.0.0
 *
 * @global array $wp_post_types List of post types.
 *
 * @see register_post_type()
 *
 * @param string $post_type The name of a registered post type.
 * @return object|null A post type object.
 */
function get_post_type_object( $post_type ) {
	global $wp_post_types;

	if ( empty($wp_post_types[$post_type]) )
		return null;

	return $wp_post_types[$post_type];
}