自定义帖子类型中的自定义元框不起作用

时间:2014-11-07 作者:Damir

作为wordpress的新手,我在我的“slider”自定义帖子类型中添加自定义元框时遇到了问题,我在一些旧的wp主题中使用了这种类型。

我收到一个警告:

Warning: call_user_func() expects parameter 1 to be a valid callback, function \'new_meta_box\' not found or invalid function name in...
这是我的代码:

/////////////////////////////////////
/* Custom post type slider        */
///////////////////////////////////

add_action( \'init\', \'create_post_type_slider\' );

function create_post_type_slider() {
    register_post_type( \'slider\',
        array(
            \'labels\' => array(
                 \'name\' => __( \'Sliders\' ),
                 \'singular_name\' => __( \'slider\' ),
                 \'search_items\' =>  __( \'Search sliders\' ),
                 \'all_items\' => __( \'All sliders\' ),
                 \'edit_item\' => __( \'Edit slider\' ),
                 \'update_item\' => __( \'Update\' ),
                 \'add_new\' => __( \'Add new slider\' ),
                 \'add_new_item\' => __( \'Add new slider\' ),
                 \'view_item\' => __( \'View slider\' ),
                 \'new_item_name\' => __( \'New slider Name\' )


            ),
        \'public\' => true,
        \'supports\' => array(\'title\',\'taxonomies\'),
        \'has_archive\' => false,
        )

    );
    flush_rewrite_rules( false );
}
/* custom post type category */
add_action( \'init\', \'create_taxonomie_sliderpos\' );
function create_taxonomie_sliderpos() {
 $labels = array(
                 \'name\' => __( \'Slider Position\' ),
                 \'singular_name\' => __( \'Slider Position\' ),
                 \'search_items\' =>  __( \'Search slider Positions\' ),
                 \'all_items\' => __( \'All Slider Position\' ),
                 \'parent_item\' => __( \'Parent Slider Position\' ),
                 \'parent_item_colon\' => __( \'Parent Category:\' ),
                 \'edit_item\' => __( \'Edit Slider Position\' ),
                 \'update_item\' => __( \'Update slider Position\' ),
                 \'add_new_item\' => __( \'Add\' ),
                 \'new_item_name\' => __( \'New slider Position Name\' ),

   );  


register_taxonomy(\'sliderpos\',\'slider\',array(
                     \'hierarchical\' => true,
                     \'labels\' => $labels,
                     \'show_ui\' => true,
                     \'show_admin_column\' => true,
   ));
 flush_rewrite_rules( false );
} 

//
$prefix = "_ct_";

$slide_info = array (

    "imglnk" => array(
        "type" => "uploadfield",
        "name" => "upload_image",
        "std" => "",
        "width" => "60%",
        "title" => __(\'Slide image:\'),
        "description" => __(\'Enter the link of the slide image or upload your own image. <strong> Image must be at least 348px height.</strong>\')),

        "captitle" => array(
        "type" => "textfield",
        "name" => $prefix."caption_title",
        "std" => "",
        "width" => "60%",
        "title" => __(\'Caption Title\'),
        "description" => __(\'Enter caption title\')),

        "captext" => array(
        "type" => "textarea",
        "name" => $prefix."caption_text",
        "std" => "",
        "title" => __(\'Caption Text\'),
        "description" => __(\'Enter caption text\')),

        "capalign" => array(
        "type" => "align",
        "name" => $prefix."align",
        "std" => "",
        "title" => __(\'Slide Alignment\'),
        "description" => __(\'\')),

        "caplink" => array(
        "type" => "textfield",
        "name" => $prefix."slide_link",
        "std" => "",
        "width" => "60%",
        "title" => __(\'Slide Link\'),
        "description" => __(\'Enter slide link with http://\')),

    );

//Create Metabox on page
function create_meta_box_slider() {    
    global $slide_info;
    add_meta_box( \'new-meta-boxes-slider\', __(\'slider Settings\'), \'new_meta_box\', \'slider\', \'normal\', \'high\', array(\'inputs\'=>$slide_info) );
}

add_action(\'admin_menu\', \'create_meta_box_slider\');

//Add $slide_info var to $meta_box_groups array
global $meta_box_groups;
$meta_box_groups[] = $slide_info;
有什么帮助吗?

谢谢

3 个回复
SO网友:Amit Mishra

嘿,把回调函数改成这样,把add\\u meta\\u box改成add\\u meta\\u box钩子

function create_meta_box_slider() {    
    add_meta_box( \'new-meta-boxes-slider\', __(\'slider Settings\'), \'new_meta_box\', \'slider\', \'normal\', \'high\' );
}

add_action(\'add_meta_boxes\', \'create_meta_box_slider\');

function new_meta_box() {
    global $meta_box_groups;
    $meta_box_groups[] = $slide_info;
}
我觉得很好用

SO网友:Jagankumar

遵循stackexchange,他们将解释如何创建元框。

http://bit.ly/1vRnqnV 您将清楚地了解自定义元框。

SO网友:Domain

add\\u meta\\u box应写在add\\u meta\\u box挂钩上

add_action( \'add_meta_boxes\', \'myplugin_add_meta_box\' );
function myplugin_add_meta_box()
{
 global $slide_info;
add_meta_box( \'new-meta-boxes-slider\', __(\'slider Settings\'), \'new_meta_box\', \'slider\', \'normal\', \'high\', array(\'inputs\'=>$slide_info) );
}

结束

相关推荐

关于从CPT SELECT Metabox保存数据的问题

我无法保存select metabox中的数据。我的代码是http://pastebin.com/BMmKzti2我错在哪里?编辑:这是我的密码 function fichasvtmbasicas_meta_box_callback( $post ) { wp_nonce_field( \'fichasvtmbasicas_meta_box\', \'fichasvtmbasicas_meta_box_nonce\' ); $fichasvtmbasicas_gera