Advertisement
Guest User

Untitled

a guest
Apr 27th, 2015
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. function trivium_build_calendar_events() {
  2.  
  3. $events_query = new WP_Query( array(
  4. 'post_type' => 'event',
  5. 'order' => 'ASC'
  6. ) );
  7.  
  8. if ( $events_query->have_posts() ) {
  9.  
  10. $calendar_events = array();
  11.  
  12. while ( $events_query->have_posts() ) {
  13. $events_query->the_post();
  14.  
  15. $coming_soon = get_field( 'coming_soon' );
  16. if ( ! $coming_soon || ! in_array( 'Hide date and mark event as "coming soon"', $coming_soon ) ) {
  17.  
  18. $event_date = DateTime::createFromFormat( 'Ymd', get_field( 'date' ) )->format( 'Y-m-d' );
  19. $coming_soon = get_field( 'coming_soon' );
  20. $city_for_event_listing_pages = get_field( 'city_for_event_listing_pages' );
  21. $city = ( ! empty( $city_for_event_listing_pages ) ) ? $city_for_event_listing_pages : get_field( 'city' );
  22. $event_location = $city . ', ' . get_field( 'state' );
  23.  
  24. $single_event_array = array(
  25. 'title' => get_the_title() . ' - ' . $event_location,
  26. 'start' => $event_date,
  27. 'url' => get_the_permalink()
  28. );
  29.  
  30. array_push( $calendar_events, $single_event_array );
  31. }
  32. }
  33.  
  34. // Convert calendar events into json objects & make available to javascript
  35. wp_localize_script( 'trivium-scripts', 'trivium_event_json_objects', json_encode( $calendar_events ) );
  36. }
  37. }
  38. add_action( 'wp_enqueue_scripts', 'trivium_build_calendar_events' );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement