If you have data stored for your events in a custom field or elsewhere (ie. my_custom_field) and you want to include as a template tag (ie. {my_custom_field}) you can do that with a bit of code in a functional plugin or in your child theme’s functions.php.
Replace my_custom_field with the custom field you want to fetch, and identifier with your calendar’s identifier:
- all-in-one-event-calendar (All-in-one Event Calendar by Time.ly)
- event-espresso (Event Espresso)
- event-organiser (Event Organizer)
- eventon (EventON)
- events-manager (Events Manager)
- eventum (Templatic/Eventum)
- geodir (Geodirectory)
- google-calendar-events (Simple Calendar)
- the-events-calendar (The Events Calendar)
- event-prime (EventPrime)
// Add the additional data for each event
function ecn_add_my_custom_field_data( $args, $post ) {
// Use additional_data to store our extra data
if ( ! isset( $args['additional_data'] ) )
$args['additional_data'] = array();
$args['additional_data']['my_custom_field'] = get_post_meta(
$post->ID,
'my_custom_field',
true
);
return $args;
}
add_filter(
'ecn_create_calendar_event_args-identifier',
'ecn_add_my_custom_field_data',
10,
2
);
// Register the template tag and description
function ecn_add_my_custom_field( $fields, $plugin ) {
if ( 'identifier' != $plugin )
return $fields;
$fields['my_custom_field'] = 'My Custom Field';
return $fields;
}
add_filter( 'ecn_available_format_tags_display', 'ecn_add_my_custom_field', 10, 2 );
Example: Advanced Custom Fields and The Events Calendar
If you’re using Advanced Custom Fields (ACF), you’ll likely want to use get_field() to fetch the data. Here’s an example with The Events Calendar (by Modern Tribe) to fetch the data from an ACF field called my_text_field:
// Add the additional data for each event
function ecn_add_my_acf_field_data( $args, $post ) {
// Use additional_data to store our extra data
if ( ! isset( $args['additional_data'] ) )
$args['additional_data'] = array();
$args['additional_data']['my_text_field'] = get_field( 'my_text_field', $post->ID );
return $args;
}
add_filter(
'ecn_create_calendar_event_args-the-events-calendar',
'ecn_add_my_acf_field_data',
10,
2
);
// Register the template tag and description
function ecn_add_my_acf_field( $fields, $plugin ) {
if ( 'the-events-calendar' != $plugin )
return $fields;
$fields['my_text_field'] = 'My Text Field';
return $fields;
}
add_filter(
'ecn_available_format_tags_display',
'ecn_add_my_acf_field',
10,
2
);
Now you can put {my_text_field} into your custom Event Calendar Newsletter template wherever you wish.
That’s it! If you’re new to Event Calendar Newsletter, you can check out a summary of the features which includes a demo video.