5 deleted 56 characters in body; edited title
source | link

Beginner: Meta box not saving

I am new to Wordpress, to this level of customizing, so I am following Noel Tock's tutorial on making an Events CPT and so far I was able to show the custom columns and the custom meta box.

Beginner: Meta box not saving

I am new to Wordpress, to this level of customizing, so I am following Noel Tock's tutorial on making an Events CPT and so far I was able to show the custom columns and the custom meta box.

Meta box not saving

I am following Noel Tock's tutorial on making an Events CPT and so far I was able to show the custom columns and the custom meta box.

4 changed
source | link
add_action('save_post', 'save_events_deets');

function save_events_deets(){
   global $post;

   if(!wp_verify_noncewp_verify_nonce1($_POST['events_nonce']$_POST['events_nonce1'], 'events_nonce''events_nonce1'))
   {    return $post -> ID;}

   if(defined('DOING_AUTOSAVE') && DOING_AUTOSAVE)
       return;

   if(!current_user_can('edit_post', $post -> ID))
   {    return $post -> ID;}

   if(!isset($_POST['event_start_date'])){
       return $post;
   }

   $updStartD = strtotime($_POST['event_start_date'] . $_POST['event_start_time']);
   update_post_meta($post -> ID, 'event_start_date', $updStartD);


   if(!isset($_POST['event_end_date'])){
       return $post;
   }

   $updEndD = strtotime($_POST['event_end_date'] . $_POST['event_end_time']);
   update_post_meta($post -> ID, 'event_end_date', $updEndD);   
}
add_action('save_post', 'save_events_deets');

function save_events_deets(){
   global $post;

   if(!wp_verify_nonce($_POST['events_nonce'], 'events_nonce'))
   {    return $post -> ID;}

   if(defined('DOING_AUTOSAVE') && DOING_AUTOSAVE)
       return;

   if(!current_user_can('edit_post', $post -> ID))
   {    return $post -> ID;}

   if(!isset($_POST['event_start_date'])){
       return $post;
   }

   $updStartD = strtotime($_POST['event_start_date'] . $_POST['event_start_time']);
   update_post_meta($post -> ID, 'event_start_date', $updStartD);


   if(!isset($_POST['event_end_date'])){
       return $post;
   }

   $updEndD = strtotime($_POST['event_end_date'] . $_POST['event_end_time']);
   update_post_meta($post -> ID, 'event_end_date', $updEndD);   
}
add_action('save_post', 'save_events_deets');

function save_events_deets(){
   global $post;

   if(!wp_verify_nonce1($_POST['events_nonce1'], 'events_nonce1'))
   {    return $post -> ID;}

   if(defined('DOING_AUTOSAVE') && DOING_AUTOSAVE)
       return;

   if(!current_user_can('edit_post', $post -> ID))
   {    return $post -> ID;}

   if(!isset($_POST['event_start_date'])){
       return $post;
   }

   $updStartD = strtotime($_POST['event_start_date'] . $_POST['event_start_time']);
   update_post_meta($post -> ID, 'event_start_date', $updStartD);


   if(!isset($_POST['event_end_date'])){
       return $post;
   }

   $updEndD = strtotime($_POST['event_end_date'] . $_POST['event_end_time']);
   update_post_meta($post -> ID, 'event_end_date', $updEndD);   
}
3 added my custom columns code
source | link

The custom columns:

function events_custom_columns($column){
global $post;
$custom = get_post_custom();
switch($column){
    case 'event_col_type':
            $eventcats = get_the_terms($post->ID, 'event_type');
            $ev_cat_html = array();
            if($eventcats){
                foreach($eventcats as $eventcat)
                    array_push($ev_cat_html, $eventcat->name);
                    echo implode($ev_cat_html, ', ');
            }
            else {
                echo 'None';
            }
    break;
    case 'event_date':
            $start = $custom['event_start_date'][0];
            $end = $custom['event_end_date'][0];

            $startdate = date('F j, Y', $start);
            $enddate = date('F j, Y', $end);

            echo $startdate . '<br><em>' . $enddate . '</em>';
    break;
    case 'event_time':

            $time_formtt = get_option('time_format');
            $starttime = $custom['event_start_date'][0];
            $endtime = $custom['event_end_date'][0];

            $startT = date($time_formtt, $starttime);
            $endT = date($time_formtt, $endtime);

            echo $startT . ' - ' . $endT;

    break;
    case 'event_location':
            echo $custom['event_location'][0];
    break;
}

}

The custom meta box: add_action('admin_init', 'events_admin_init');

The custom meta box: add_action('admin_init', 'events_admin_init');

The custom columns:

function events_custom_columns($column){
global $post;
$custom = get_post_custom();
switch($column){
    case 'event_col_type':
            $eventcats = get_the_terms($post->ID, 'event_type');
            $ev_cat_html = array();
            if($eventcats){
                foreach($eventcats as $eventcat)
                    array_push($ev_cat_html, $eventcat->name);
                    echo implode($ev_cat_html, ', ');
            }
            else {
                echo 'None';
            }
    break;
    case 'event_date':
            $start = $custom['event_start_date'][0];
            $end = $custom['event_end_date'][0];

            $startdate = date('F j, Y', $start);
            $enddate = date('F j, Y', $end);

            echo $startdate . '<br><em>' . $enddate . '</em>';
    break;
    case 'event_time':

            $time_formtt = get_option('time_format');
            $starttime = $custom['event_start_date'][0];
            $endtime = $custom['event_end_date'][0];

            $startT = date($time_formtt, $starttime);
            $endT = date($time_formtt, $endtime);

            echo $startT . ' - ' . $endT;

    break;
    case 'event_location':
            echo $custom['event_location'][0];
    break;
}

}

The custom meta box: add_action('admin_init', 'events_admin_init');

2 added 1530 characters in body
source | link
1
source | link