我需要在我的WordPress自定义帖子中注册一个metabox,但前提是帖子永久保存在数据库中。
我的意思是,当用户单击“添加新内容”时,我不想显示metabox。当用户在页面刷新后单击“发布”时,将显示metabox。
帖子状态无关紧要(已发布、私有或其他)
有什么想法吗?
我需要在我的WordPress自定义帖子中注册一个metabox,但前提是帖子永久保存在数据库中。
我的意思是,当用户单击“添加新内容”时,我不想显示metabox。当用户在页面刷新后单击“发布”时,将显示metabox。
帖子状态无关紧要(已发布、私有或其他)
有什么想法吗?
作为@m0r7if3r解决方案的替代方案add_meta_boxes
hook可以选择传递两个变量,post类型和post对象。您可以使用此选项有条件地添加metabox。新帖子的帖子状态为“自动草稿”。
add_action( \'add_meta_boxes\', \'myplugin_add_custom_box\',10,2);
function myplugin_add_custom_box($post_type, $post) {
if($post->post_status != \'auto-draft\'){
add_meta_box(
\'myplugin_sectionid\',
__( \'My Post Section Title\', \'myplugin_textdomain\' ),
\'myplugin_inner_custom_box\',
\'post\' );
}
}
您应该能够将呼叫筛选到add_meta_box()
有条件地使用$current_screen
变量或get_current_screen()
. 用户唯一不应该看到该框的时间是打开post-new.php
, 一旦他们离开该页面,就会进行某种形式的保存。
我在写文章时使用了多个metabox面板。在我的函数中,我注册了多个元数据库:$prefix = \'dbt_\'; $meta_boxes = array(); $meta_boxes[] = array( \'id\' => \'general_information\', \'title\' => \'General Information\', \'pages\' => array(\'post\