WordPress检查文章类型是否存在:post_type_exists

WordPress函数post_type_exists检查文章类型是否存在,如果已存在则返回true。通常在使用函数register_post_type()注册文章类型前应该先使用post_type_exists()函数进行检查。

post_type_exists( string $post_type )

函数参数

$post_type

字符串

文章类型

函数使用示例

if ( post_type_exists( 'page' ) ) {
	echo '文章类型page已存在';
} else {
	echo '文章类型page不存在';
}

扩展阅读

post_type_exists()函数位于:wp-includes/post.php

相关函数:

阿里云