Skip to content

Instantly share code, notes, and snippets.

@kellenmace
Created March 10, 2015 16:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kellenmace/17e1a9d0ec5b5a872e5a to your computer and use it in GitHub Desktop.
Save kellenmace/17e1a9d0ec5b5a872e5a to your computer and use it in GitHub Desktop.
localize call
function trivium_build_calendar_events() {
$events_query = new WP_Query( array(
'post_type' => 'event',
'order' => 'ASC'
) );
if ( $events_query->have_posts() ) {
$calendar_events = array();
while ( $events_query->have_posts() ) {
$events_query->the_post();
$coming_soon = get_field( 'coming_soon' );
if ( ! $coming_soon || ! in_array( 'Hide date and mark event as "coming soon"', $coming_soon ) ) {
$event_date = DateTime::createFromFormat( 'Ymd', get_field( 'date' ) )->format( 'Y-m-d' );
$coming_soon = get_field( 'coming_soon' );
$city_for_event_listing_pages = get_field( 'city_for_event_listing_pages' );
$city = ( ! empty( $city_for_event_listing_pages ) ) ? $city_for_event_listing_pages : get_field( 'city' );
$event_location = $city . ', ' . get_field( 'state' );
$single_event_array = array(
'title' => get_the_title() . ' - ' . $event_location,
'start' => $event_date,
'url' => get_the_permalink()
);
array_push( $calendar_events, $single_event_array );
}
}
// Convert calendar events into json objects & make available to javascript
wp_localize_script( 'trivium-scripts', 'trivium_event_json_objects', json_encode( $calendar_events ) );
}
}
add_action( 'wp_enqueue_scripts', 'trivium_build_calendar_events' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment