Home › Forums › Front-end Issues › Integrate ACF in "All-in-one Event Calendar" › Reply To: Integrate ACF in "All-in-one Event Calendar"
Hi Elliot!
The developer of the plugin told me to insert the custom field created with Acf in the save_post function of the plugin. Here is the code, can you help me?
function save_post( $post_id, $post ) {
global $wpdb, $ai1ec_events_helper, $ai1ec_importer_plugin_helper;
// verify this came from the our screen and with proper authorization,
// because save_post can be triggered at other times
if( isset( $_POST[AI1EC_POST_TYPE] ) && ! wp_verify_nonce( $_POST[AI1EC_POST_TYPE], 'ai1ec' ) ) {
return;
} else if( ! isset( $_POST[AI1EC_POST_TYPE] ) ) {
return;
}
if( isset( $post->post_status ) && $post->post_status == 'auto-draft' ) {
return;
}
// verify if this is not inline-editing
if( isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'inline-save' ) {
return;
}
// verify that the post_type is that of an event
if( isset( $_POST['post_type'] ) && $_POST['post_type'] != AI1EC_POST_TYPE ) {
return;
}
// LABEL:magicquotes
// remove WordPress <code>magical</code> slashes - we work around it ourselves
$_POST = stripslashes_deep( $_POST );
$all_day = isset( $_POST['ai1ec_all_day_event'] ) ? 1 : 0;
$instant_event = isset( $_POST['ai1ec_instant_event'] ) ? 1 : 0;
$start_time = isset( $_POST['ai1ec_start_time'] ) ? $_POST['ai1ec_start_time'] : '';
$end_time = isset( $_POST['ai1ec_end_time'] ) ? $_POST['ai1ec_end_time'] : '';
$venue = isset( $_POST['ai1ec_venue'] ) ? $_POST['ai1ec_venue'] : '';
$address = isset( $_POST['ai1ec_address'] ) ? $_POST['ai1ec_address'] : '';
$compilatore = isset( $_POST['ai1ec_event_1_nome_e_cognome_compilatore'] ) ? $_POST['ai1ec_event_1_nome_e_cognome_compilatore'] : '';
$city = isset( $_POST['ai1ec_city'] ) ? $_POST['ai1ec_city'] : '';
$province = isset( $_POST['ai1ec_province'] ) ? $_POST['ai1ec_province'] : '';
$postal_code = isset( $_POST['ai1ec_postal_code'] ) ? $_POST['ai1ec_postal_code'] : '';
$country = isset( $_POST['ai1ec_country'] ) ? $_POST['ai1ec_country'] : '';
$google_map = isset( $_POST['ai1ec_google_map'] ) ? 1 : 0;
$cost = isset( $_POST['ai1ec_cost'] ) ? $_POST['ai1ec_cost'] : '';
$is_free = isset( $_POST['ai1ec_is_free'] ) ? (bool)$_POST['ai1ec_is_free'] : false;
$ticket_url = isset( $_POST['ai1ec_ticket_url'] ) ? $_POST['ai1ec_ticket_url'] : '';
$contact_name = isset( $_POST['ai1ec_contact_name'] ) ? $_POST['ai1ec_contact_name'] : '';
$contact_phone = isset( $_POST['ai1ec_contact_phone'] ) ? $_POST['ai1ec_contact_phone'] : '';
$contact_email = isset( $_POST['ai1ec_contact_email'] ) ? $_POST['ai1ec_contact_email'] : '';
$contact_url = isset( $_POST['ai1ec_contact_url'] ) ? $_POST['ai1ec_contact_url'] : '';
$show_coordinates = isset( $_POST['ai1ec_input_coordinates'] )? 1 : 0;
$longitude = isset( $_POST['ai1ec_longitude'] ) ? $_POST['ai1ec_longitude'] : '';
$latitude = isset( $_POST['ai1ec_latitude'] ) ? $_POST['ai1ec_latitude'] : '';
$post_twitter = isset( $_POST['ai1ec_oauth_provider_twitter'] )
? (bool)$_POST['ai1ec_oauth_provider_twitter']
: false;
$rrule = NULL;
$exrule = NULL;
$exdate = NULL;
// if rrule is set, convert it from local to UTC time
if( isset( $_POST['ai1ec_repeat'] ) && ! empty( $_POST['ai1ec_repeat'] ) )
$rrule = $ai1ec_events_helper->ics_rule_to_gmt( $_POST['ai1ec_rrule'] );
// if exrule is set, convert it from local to UTC time
if (
isset( $_POST['ai1ec_exclude'] ) &&
! empty( $_POST['ai1ec_exclude'] ) &&
NULL !== $rrule // no point for exclusion, if repetition is not set
) {
$exrule = $this->_merge_exrule(
$_POST['ai1ec_exrule'],
$_POST['ai1ec_rrule']
);
$exrule = $ai1ec_events_helper->ics_rule_to_gmt( $exrule );
}
// if exdate is set, convert it from local to UTC time
if( isset( $_POST['ai1ec_exdate'] ) && ! empty( $_POST['ai1ec_exdate'] ) )
$exdate = $ai1ec_events_helper->exception_dates_to_gmt( $_POST['ai1ec_exdate'] );
$is_new = false;
$event = null;
try {
$event = new Ai1ec_Event( $post_id ? $post_id : null );
} catch( Ai1ec_Event_Not_Found $e ) {
// Post exists, but event data hasn't been saved yet. Create new event
// object.
$is_new = true;
$event = new Ai1ec_Event();
$event->post_id = $post_id;
}
// If the events is marked as instant, make it last 30 minutes
if( $instant_event ) {
$end_time = $start_time + 1800;
}
$event->start = $ai1ec_events_helper->local_to_gmt( $start_time );
$event->end = $ai1ec_events_helper->local_to_gmt( $end_time );
$event->allday = $all_day;
$event->instant_event = $instant_event;
$event->venue = $venue;
$event->compilatore = $compilatore;
$event->address = $address;
$event->city = $city;
$event->province = $province;
$event->postal_code = $postal_code;
$event->country = $country;
$event->show_map = $google_map;
$event->cost = $cost;
$event->is_free = $is_free;
$event->ticket_url = $ticket_url;
$event->contact_name = $contact_name;
$event->contact_phone = $contact_phone;
$event->contact_email = $contact_email;
$event->contact_url = $contact_url;
$event->recurrence_rules = $rrule;
$event->exception_rules = $exrule;
$event->exception_dates = $exdate;
$event->show_coordinates = $show_coordinates;
$event->longitude = trim( $longitude ) !== '' ? (float) $longitude : NULL;
$event->latitude = trim( $latitude ) !== '' ? (float) $latitude : NULL;
// if we are not saving a draft, give the event to the plugins. Also do not pass events that are imported from facebook
if( $post->post_status !== 'draft' && $event->facebook_status !== Ai1ecFacebookConnectorPlugin::FB_IMPORTED_EVENT ) {
$ai1ec_importer_plugin_helper->handle_post_event( $event, 'save' );
}
$saved_post_id = $event->save( ! $is_new );
if ( $post_twitter ) {
if ( ! add_post_meta(
$saved_post_id,
'_ai1ec_post_twitter',
'pending',
true
) ) {
update_post_meta(
$saved_post_id,
'_ai1ec_post_twitter',
'pending'
);
}
}
$ai1ec_events_helper->delete_event_cache( $post_id );
$ai1ec_events_helper->cache_event( $event );
// LABEL:magicquotes
// restore <code>magic</code> WordPress quotes to maintain compatibility
$_POST = add_magic_quotes( $_POST );
return $event;
}
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.