0

As a wordpress newbie I am having problems in adding custom meta box in my "slider" custom post type which I used in some old wp theme.

I'm getting a warning:

Warning: call_user_func() expects parameter 1 to be a valid callback, function 'new_meta_box' not found or invalid function name in...

Here is my code:

/////////////////////////////////////
/* 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;

Any help?

Thanks!

1

Hey Change Callback function to like this and add_meta_box to add_meta_boxes hook

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;
}

I think it work fine

0

follow the stackexchange they will explained how you are going to create a meta boxes.

http://bit.ly/1vRnqnV you will get an clear idea about the custom meta box.

0

add_meta_box should be written on add_meta_boxes hook

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) );
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.