[英]WordPress if post.php but only for one Custom Post Type
这是为后端。 管理区域。 我有一个脚本可以运行某些功能,但仅适用于“事件日历”创建的“事件”自定义帖子类型。 目前,我的functions.php中正在运行此脚本:
if ($page == "post-new.php" OR $page == "post.php" ) {
do something.....;
}
因此它可以工作,但可以用于任何具有post-new.php或post.php的东西。 不好,因为这涉及仅与事件CPT相关的字段。 我如何才能使其仅在此CPT上工作?
通常,您可以依靠get_current_screen()
函数来返回您所在管理页面的数据:
$current_screen = get_current_screen();
if( $current_screen->base == 'post' && $current_screen->post_type == 'your-post-type-here' ){
// Do things
}
还有$post_type
全局变量,但说实话,我认为它使用的不是太多。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.