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

文 / @WordPress主题

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

相关函数:

  • get_post_type_object()
  • register_post_type()
添加UTHEME为好友
扫码添加UTHEME微信为好友
· 分享WordPress相关技术文章,主题上新与优惠动态早知道。
· 微信端最大WordPress社群,限时免费入群。