How to add support for additional ICS fields
Last Updated: August 22, 2016
All the below PHP code must be placed in your theme functions.php file for them to work correctly.
Step #1
Include additional fields in the fields array.
add_filter('evoics_additional_ics_fields', 'evoics_fields', 10, 1); function evoics_fields($fields){ $fields[] = 'evcal_subtitle'; return $fields; }
So here we are including the field evcal_subtitle in the fields array that will be cycle through to fetch values and to save values. You can refer here for other event post meta fields variable names http://www.myeventon.com/documentation/event-post-meta-variables/
Step #2
Display the imported additional field values in fetched events screen as hidden field so that can be passed on to saving the value.
add_filter('evoics_additional_data_validation', 'evoics_validate',10,1); function evoics_validate($ics_data){ if(!empty($ics_data['SUBTITLE'])){ $ics_data = array_merge($ics_data, array( 'evcal_subtitle'=>$ics_data['SUBTITLE'] )); } return $ics_data; }
Step #3
Saving the field values. By default the additional field will be saved as event post meta using the variable name you gave. You can also use the below pluggable hook to perform your own saving function within the fields loop. $post_id here represents the already created event ID that can be used to associate things to the correct event.
add_action('evoics_save_event_custom_data','evoics_save_inloop',10,3); function evoics_save_inloop($post_id, $post_data, $field){ if($field!= 'evcal_subtitle') return false; // perform your own saving function update_post_meta($post_id, $field, $post_data[$field]); // You can use below to save taxonomy values eg. for event type category terms // wp_set_post_terms( $post_id, $post_data[$field], 'event_type'); }
You can also use the below pluggable action to save outside the fields loop.
do_action('evoics_save_additional_data', $post_id, $post_data);
NOTE: When you add an extra field make sure you are associating that with the correct event post meta variable name for Event — you can find the commonly used event post meta variable names in here http://www.myeventon.com/documentation/event-post-meta-variables/
Did this article help you?