Wordpress 将自定义元框显示到管理侧边栏不工作

Wordpress 将自定义元框显示到管理侧边栏不工作,wordpress,Wordpress,我创建了一个自定义元框,在管理区域的post显示中显示一些内容,并希望它显示在侧栏中,而不是所见即所得编辑器的下方。我在上下文中添加了“side”,但什么也没发生!我已经玩了好几个小时了,没有任何运气 这是我的代码: function add_custom_meta_box() { add_meta_box ( 'custom_meta_box', 'Custom Meta Box Title', 'show_custom_meta_box

我创建了一个自定义元框,在管理区域的post显示中显示一些内容,并希望它显示在侧栏中,而不是所见即所得编辑器的下方。我在上下文中添加了“side”,但什么也没发生!我已经玩了好几个小时了,没有任何运气

这是我的代码:

function add_custom_meta_box() {
    add_meta_box (
        'custom_meta_box',
        'Custom Meta Box Title',
        'show_custom_meta_box',
        'post',
        'side',
        'high'
    );
}
add_action('add_meta_boxes', 'add_custom_meta_box');

function show_custom_meta_box() {
    // here i have all the code
}
根据此调整,以下命令将强制自定义元框进入侧柱中的第二个位置

检查注释并注意
admin\u init

只有当用户自己没有重新安排位置时,它才起作用。注册新用户时,会为其设置位置,因为钩子
admin\u init
user\u register
连接到同一回调函数

// This fires at **every** page load, a better hook must be found
add_action( 'admin_init', 'set_user_metaboxes_so_14183498' ); 

// This fires when a new user is created
add_action( 'user_register', 'set_user_metaboxes_so_14183498' );  

function set_user_metaboxes_so_14183498( $user_id = null ) 
{
    // This is the metakey we will need to update  
    $meta_key = 'meta-box-order_post';

    // So this can be used without hooking into user_register
    if( !$user_id )
        $user_id = get_current_user_id(); 

    // Set the default order if it has not been set yet by the user. 
    // These are WP handles, PLUS our custom meta box handle
    if ( ! get_user_meta( $user_id, $meta_key, true ) ) 
    {
        $meta_value = array(
            'side' => 'submitdiv,custom_meta_box,formatdiv,postimagediv',
            'normal' => 'postcustom,commentsdiv,slugdiv,revisionsdiv',
            'advanced' => '',
        );
        update_user_meta( $user_id, $meta_key, $meta_value );
    }
}
根据此调整,以下命令将强制自定义元框进入侧柱中的第二个位置

检查注释并注意
admin\u init

只有当用户自己没有重新安排位置时,它才起作用。注册新用户时,会为其设置位置,因为钩子
admin\u init
user\u register
连接到同一回调函数

// This fires at **every** page load, a better hook must be found
add_action( 'admin_init', 'set_user_metaboxes_so_14183498' ); 

// This fires when a new user is created
add_action( 'user_register', 'set_user_metaboxes_so_14183498' );  

function set_user_metaboxes_so_14183498( $user_id = null ) 
{
    // This is the metakey we will need to update  
    $meta_key = 'meta-box-order_post';

    // So this can be used without hooking into user_register
    if( !$user_id )
        $user_id = get_current_user_id(); 

    // Set the default order if it has not been set yet by the user. 
    // These are WP handles, PLUS our custom meta box handle
    if ( ! get_user_meta( $user_id, $meta_key, true ) ) 
    {
        $meta_value = array(
            'side' => 'submitdiv,custom_meta_box,formatdiv,postimagediv',
            'normal' => 'postcustom,commentsdiv,slugdiv,revisionsdiv',
            'advanced' => '',
        );
        update_user_meta( $user_id, $meta_key, $meta_value );
    }
}

你能确认你使用的是哪个版本的WordPress吗?如果我应用你的确切代码,它会呈现在侧面,在
Publish
meta框的顶部。在空白安装中尝试。您好@Jared Cobb非常感谢您的回复,我使用的版本是3.5Hi@brasofilo,我如何在空白安装中尝试它?不需要是空白安装(您可以在服务器的文件夹中安装另一个WP),只需创建一个新用户并登录即可。您能确认您正在使用的WordPress版本吗?如果我应用您的确切代码,它会在
Publish
meta框顶部的侧面呈现。在空白安装中尝试。您好@Jared Cobb非常感谢您的回复,我使用的版本是3.5Hi@brasofilo,我如何在空白安装中尝试它?不需要是空白安装(您可以在服务器的文件夹中安装另一个WP),只需创建一个新用户并登录,以便进行检查。是否有方法重置管理员配置?更新后的metabox适用于新用户,但作为管理员,我仍然可以在旧位置看到metabox。我认为最简单的方法是查看数据库。我不认为删除一个元值会带来麻烦,但像往常一样,备份只是为了在损坏数据库之前以防万一,有没有办法重置管理配置?更新后的metabox适用于新用户,但作为管理员,我仍然可以在旧位置看到metabox。我认为最简单的方法是查看数据库。我不认为删除一个元值会带来麻烦,但像往常一样,备份只是为了在和数据库发生冲突之前以防万一