Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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' );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement