0

Here is my custom type post code. I want to add the meta box in there...

function events_cust(){
      $label = array(
            'name' => _x('Events'),
            'singular_name' => _x('events'),
            'menu_name'  => __('Events'),
            'add_new' => __('Add Event'),
            'add_new_item' => __ ('Add New Event'),
            'all_item' => __('All Event'),
            'edit_item' => __('Edit Event'),
            'new_item' => __('New Event'),
            'view_item' => __('View Event'),
            'update_item' => __('update Event'),
            'search_item' => __('Search Event')
            );
            $attr = array(
            'label' => __('Events'),
            'description' => __('Event'),
            'labels' => $label,
            'supports'  => array('title','editor','thumbnail'),
            'taxonomies' => array('genres'),
            'hiecrarhical' => false,
            'public' => true,
            'show_ui' => true,
            'show_in_menu' => true,
            'show_in_adim_bar' => true,
            'menu_position'       => 5,
   'can_export'          => true,
   'has_archive'         => true,
   'exclude_from_search' => false,
   'publicly_queryable'  => true,
   'capability_type'     => 'post',
            );
            register_post_type('events-lists',$attr);
      }
      add_action( 'init', 'events_cust', 0 );

   add_action('add_meta_boxes','create_events_metaboxes');
   function create_events_metaboxes(){
      add_meta_box('events-meta-box','Events Details','show_events_metaboxes','events-lists','normal','hight');
   }

   function show_events_metaboxes(){
    echo 'Hello Meta box';
   }

What's wrong with us.

1

Try below code.

add_action('add_meta_boxes','create_events_metaboxes'); 
function create_events_metaboxes() { 
  add_meta_box('events-meta-box','Events Details','show_events_metaboxes','events-lists'); 
}

function show_events_metaboxes($post){ echo 'Hello Meta box'; }

Hope this will helps you.

Refer from add_meta_box

  • You are missing one argument $context.Try add_meta_box('events-meta-box','Events Details','show_events_metaboxes','events-lists','normal','high','height'); code. – AddWeb Solution Pvt Ltd Dec 27 '16 at 12:27
  • content argument already applied(normal)...... – mahesh kumar Dec 27 '16 at 12:33
  • Sorry i got you.Your $priority argument is wrong its "high" instead of "hight". – AddWeb Solution Pvt Ltd Dec 27 '16 at 12:38
  • i'm cheak the all add_meta_box argument .....What it's not working – mahesh kumar Dec 27 '16 at 12:45
  • I try add_meta_box('events-meta-box','Events Details','show_events_metaboxes','events-lists','normal','high'); and its working. – AddWeb Solution Pvt Ltd Dec 27 '16 at 12:48
0

ACF may help in your farther run. Try it if you need meta boxes more organised.

0

Try this:

    function event_custom_meta_boxes( $post_type, $post ) {
        add_meta_box( 
            'my-meta-box',
            __( 'My Meta Box' ),
            'render_my_meta_box',
            'post', //post type, event, product etc. 
            'normal',
            'default'
        );
    }
    add_action( 'add_meta_boxes', 'event_custom_meta_boxes', 10, 2 );

  function render_my_meta_box(){
    echo "Hello World!";
  }

for more reference: https://codex.wordpress.org/Plugin_API/Action_Reference/add_meta_boxes

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.