'ATS_Type', 'value' => $type, 'compare' => '=', ); if ( empty( $args['meta_query'] ) || ! is_array( $args['meta_query'] ) ) { $args['meta_query'] = array( $type_clause ); return $args; } $existing = $args['meta_query']; if ( ! isset( $existing['relation'] ) ) { $existing = array_merge( array( 'relation' => 'AND' ), $existing ); } else { $existing['relation'] = 'AND'; } $existing[] = $type_clause; $args['meta_query'] = $existing; return $args; } static function ats_shortcode_event_listCB( $atts ) { $postConfigType = get_option( 'agile_field_config_integration_type' ); $postTypeSet = ''; switch ( $postConfigType ) { case 'none': $postTypeSet = 'agile_post'; break; case 'event_champ': $postTypeSet = 'event'; break; case 'custom': $postTypeSet = agile_tix_Options::sanitize_theme_custom_map_post_type( get_option( 'agile_field_theme_custom_map_post_type' ) ); if ( '' === $postTypeSet ) { $postTypeSet = 'agile_post'; } break; case 'amy_movie': $postTypeSet = 'amy_movie'; break; default: $postTypeSet = 'agile_post'; // fallback for unexpected values } $atts = shortcode_atts( array( 'posttype' => $postTypeSet, 'type' => '', 'title' => 'EVENTS', ), $atts, 'agiletix_event_list' ); $postType = sanitize_key( $atts['posttype'] ); $type = sanitize_text_field( $atts['type'] ); $list_title = sanitize_text_field( $atts['title'] ); if ( '' === $list_title ) { $list_title = 'EVENTS'; } $args = array( 'numberposts' => 99, 'post_type' => $postType, 'fields' => 'ids', ); $args = self::append_type_meta_query( $args, $type ); $posts = get_posts( $args ); $eventsData = array(); $allGenres = array(); $eventDates = array(); foreach ( $posts as $post_id ) { $eventID = get_post_meta( $post_id, 'ATS_EventID', true ); if ( $eventID ) { $title = get_the_title( $post_id ); $genres = wp_get_object_terms( $post_id, 'agile_genre' ); $genreNames = array(); if ( ! is_wp_error( $genres ) && ! empty( $genres ) ) { foreach ( $genres as $genre ) { $genreNames[] = $genre->name; $allGenres[] = $genre->name; } } // Collect event dates for calendar $showtimes = get_post_meta( $post_id, 'ATS_ShowTimes', true ); if ( $showtimes && is_array( $showtimes ) ) { foreach ( $showtimes as $showtimeData ) { if ( is_array( $showtimeData ) ) { foreach ( $showtimeData as $showtime => $purchaseLink ) { $date = new DateTime( $showtime ); $eventDates[] = $date->format( 'Y-m-d' ); } } } } $eventsData[] = array( 'id' => $post_id, 'title' => $title, 'first_letter' => strtoupper( substr( $title, 0, 1 ) ), 'genres' => $genreNames, ); } } // Get all unique starting letters, genres, and dates $availableLetters = array_unique( array_column( $eventsData, 'first_letter' ) ); $availableGenres = array_unique( $allGenres ); $availableDates = array_unique( $eventDates ); sort( $availableGenres ); sort( $availableDates ); self::enqueue_event_list_assets(); $listContent = '
'; $listContent .= '

' . esc_html( $list_title ) . '

'; $listContent .= "View A-Z | View by Date
"; // A-Z filter $listContent .= '
'; $listContent .= ''; // if we don't have any genres to list, don't bother showing the button $genreBtnClass = count( $availableGenres ) < 1 ? ' ats_event_list_filter_toggle_btn--hidden' : ''; // Genre Filter $listContent .= ''; // Calendar Filter $listContent .= '
'; $listContent .= ''; // Add calendar overlay and calendar $listContent .= '
'; $listContent .= '
'; $listContent .= '
'; $listContent .= ''; $listContent .= ''; $listContent .= '
'; $listContent .= '
'; $listContent .= '
'; $listContent .= '
S
M
T
W
T
F
S
'; $listContent .= '
'; $listContent .= '
'; $listContent .= '
'; $listContent .= '
'; $listContent .= ''; $listContent .= ''; $listContent .= '
'; $listContent .= '
'; $listContent .= '
'; $listContent .= '
'; // Add the alphabetical filter $listContent .= '
'; $listContent .= '
'; $listContent .= '
'; $listContent .= ''; // create A-Z buttons, disable those without events for ( $i = 65; $i <= 90; $i++ ) { $letter = chr( $i ); $hasEvents = in_array( $letter, $availableLetters ); $disabledClass = $hasEvents ? '' : ' ats_filter_btn_disabled'; $disabled = $hasEvents ? '' : ' disabled'; $listContent .= ''; } $listContent .= '
'; $listContent .= '
'; // add genre filter $listContent .= '
'; $listContent .= '
'; $listContent .= '
'; $listContent .= ''; // Create genre buttons foreach ( $availableGenres as $genre ) { $listContent .= ''; } $listContent .= '
'; $listContent .= '
'; // Generate events HTML $listContent .= "
"; $showtimeList = array(); foreach ( $posts as $post_id ) { $eventID = get_post_meta( $post_id, 'ATS_EventID', true ); if ( $eventID ) { $title = get_the_title( $post_id ); $firstLetter = strtoupper( substr( $title, 0, 1 ) ); $permalink = get_permalink( $post_id ); $thumb_id = get_post_thumbnail_id( $post_id ); $thumbnail = $thumb_id ? wp_get_attachment_image( $thumb_id, 'medium', false, array( 'class' => 'event-thumbnail' ) ) : ''; $excerpt = get_the_excerpt( $post_id ); $content = get_post_field( 'post_content', $post_id ); $description = ! empty( $excerpt ) ? $excerpt : wp_trim_words( $content, 30, '...' ); // Get genres for this event $genres = wp_get_object_terms( $post_id, 'agile_genre' ); $genreNames = array(); if ( ! is_wp_error( $genres ) && ! empty( $genres ) ) { foreach ( $genres as $genre ) { $genreNames[] = $genre->name; } } $genreData = ! empty( $genreNames ) ? implode( ',', $genreNames ) : ''; // Get event dates and times - collect all dates for this event $eventDatesList = array(); $showtimes = get_post_meta( $post_id, 'ATS_ShowTimes', true ); if ( $showtimes && is_array( $showtimes ) ) { foreach ( $showtimes as $showtimeData ) { if ( is_array( $showtimeData ) ) { foreach ( $showtimeData as $showtime => $purchaseLink ) { $date = new DateTime( $showtime ); $eventDatesList[] = $date->format( 'Y-m-d' ); } } } } $eventDatesData = ! empty( $eventDatesList ) ? implode( ',', array_unique( $eventDatesList ) ) : ''; $showtimeList[] = $showtimes; $listContent .= '
'; $listContent .= '
'; // Thumbnail if ( $thumbnail ) { $listContent .= '
'; $listContent .= '' . $thumbnail . ''; $listContent .= '
'; } $listContent .= '
'; $listContent .= '

' . esc_html( $title ) . '

'; $listContent .= '

' . esc_html( $description ) . '

'; if ( $showtimes && is_array( $showtimes ) ) { $groupedShowtimes = array(); foreach ( $showtimes as $showtimeData ) { if ( is_array( $showtimeData ) ) { foreach ( $showtimeData as $showtimeString => $purchaseLink ) { $date = new DateTime( $showtimeString ); $dateKey = $date->format( 'Y-m-d' ); $time = $date->format( 'H:i' ); if ( ! isset( $groupedShowtimes[ $dateKey ] ) ) { $groupedShowtimes[ $dateKey ] = array( 'date' => $date, 'times' => array(), ); } $groupedShowtimes[ $dateKey ]['times'][] = array( 'time' => $time, 'purchaseLink' => $purchaseLink, ); } } } ksort( $groupedShowtimes ); // generate unique identifier for this showtimes list $uniqueId = uniqid( 'showtimes_' ); $listContent .= '
'; $index = 0; $totalDays = count( $groupedShowtimes ); $hasMoreThanFive = $totalDays > 5; foreach ( $groupedShowtimes as $dateData ) { $isHidden = false; if ( $hasMoreThanFive && $index >= 5 ) { $isHidden = true; } $date = $dateData['date']; $month = $date->format( 'M' ); $day = $date->format( 'j' ); $hiddenClass = $isHidden ? ' ats_showtime_hidden_' . esc_attr( $uniqueId ) : ''; $listContent .= '
'; $dateString = $month . ' ' . $day; $paddedDate = str_pad( $dateString, 6, ' ', STR_PAD_RIGHT ); $listContent .= '' . esc_html( $paddedDate ) . ' - '; // sort times while preserving purchase link association usort( $dateData['times'], function ( $a, $b ) { return strcmp( $a['time'], $b['time'] ); } ); foreach ( $dateData['times'] as $timeData ) { $time = $timeData['time']; $purchaseLink = $timeData['purchaseLink']; $timeObj = DateTime::createFromFormat( 'H:i', $time ); $formattedTime = $timeObj ? $timeObj->format( 'g:i A' ) : $time; $paddedTime = str_pad( $formattedTime, 8, ' ', STR_PAD_RIGHT ); $listContent .= '' . esc_html( $paddedTime ) . ''; } $listContent .= '
'; $index += 1; } // add "Show More" button at the bottom if there are more than 5 days if ( $hasMoreThanFive ) { $moreDaysCount = $totalDays - 5; $listContent .= '
'; $listContent .= ''; $listContent .= '
'; } $listContent .= '
'; } else { // Fallback to single date if showtimes not available $firstEndDate = get_post_meta( $post_id, 'ATS_firstEndDate', true ); if ( $firstEndDate ) { $date = new DateTime( $firstEndDate ); $readableDate = $date->format( 'D, M j \a\t g:i A' ); $listContent .= '
' . esc_html( $readableDate ) . '
'; } } // More Details button $listContent .= 'More Details'; $listContent .= '
'; // .event-details $listContent .= '
'; // .event-content $listContent .= '
'; // .event-item } } $listContent .= '
'; // #ats_event_list_AZView $listContent .= "
"; // build the event list by date - collect events with their showtimes $groupedShowDays = array(); foreach ( $posts as $post_id ) { $eventID = get_post_meta( $post_id, 'ATS_EventID', true ); if ( $eventID ) { $title = get_the_title( $post_id ); $firstLetter = strtoupper( substr( $title, 0, 1 ) ); // add first letter for filtering $permalink = get_permalink( $post_id ); $thumb_id = get_post_thumbnail_id( $post_id ); $thumbnail = $thumb_id ? wp_get_attachment_image( $thumb_id, 'thumbnail', false, array( 'class' => 'event-thumbnail-small' ) ) : ''; $excerpt = get_the_excerpt( $post_id ); $content = get_post_field( 'post_content', $post_id ); $description = ! empty( $excerpt ) ? $excerpt : wp_trim_words( $content, 15, '...' ); // get genres for this event $genres = wp_get_object_terms( $post_id, 'agile_genre' ); $genreNames = array(); if ( ! is_wp_error( $genres ) && ! empty( $genres ) ) { foreach ( $genres as $genre ) { $genreNames[] = $genre->name; } } $genreData = ! empty( $genreNames ) ? implode( ',', $genreNames ) : ''; $showtimes = get_post_meta( $post_id, 'ATS_ShowTimes', true ); if ( $showtimes && is_array( $showtimes ) ) { foreach ( $showtimes as $showtimeData ) { if ( is_array( $showtimeData ) ) { foreach ( $showtimeData as $showtime => $purchaseLink ) { $date = new DateTime( $showtime ); $dateKey = $date->format( 'Y-m-d' ); $time = $date->format( 'H:i' ); if ( ! isset( $groupedShowDays[ $dateKey ] ) ) { $groupedShowDays[ $dateKey ] = array( 'date' => $date, 'events' => array(), ); } // check if this event is already added for this date $eventExists = false; foreach ( $groupedShowDays[ $dateKey ]['events'] as &$existingEvent ) { if ( $existingEvent['id'] == $post_id ) { // $existingEvent['times'][] = $time; $existingEvent['times'][] = array( 'time' => $time, 'purchaseLink' => $purchaseLink, ); $eventExists = true; break; } } // if event doesn't exist for this date, add it if ( ! $eventExists ) { $groupedShowDays[ $dateKey ]['events'][] = array( 'id' => $post_id, 'title' => $title, 'first_letter' => $firstLetter, // add first letter for filtering 'permalink' => $permalink, 'thumbnail' => $thumbnail, 'description' => $description, 'genres' => $genreData, // 'times' => [$time] 'times' => array( array( 'time' => $time, 'purchaseLink' => $purchaseLink, ), ), ); } } } } } } } ksort( $groupedShowDays ); // generate the timeline HTML if ( ! empty( $groupedShowDays ) ) { $listContent .= '
'; foreach ( $groupedShowDays as $dateKey => $dayData ) { $date = $dayData['date']; $dayName = $date->format( 'D' ); // short day name $monthDay = $date->format( 'M j' ); // short month and day $listContent .= '
'; $listContent .= '
'; $listContent .= '
' . esc_html( $dayName . ' ' . $monthDay ) . '
'; $listContent .= '
'; $listContent .= '
'; // sort events by their earliest showtime for this day usort( $dayData['events'], function ( $a, $b ) { $aEarliest = min( array_column( $a['times'], 'time' ) ); $bEarliest = min( array_column( $b['times'], 'time' ) ); return strcmp( $aEarliest, $bEarliest ); } ); foreach ( $dayData['events'] as $event ) { usort( $event['times'], function ( $a, $b ) { return strcmp( $a['time'], $b['time'] ); } ); // add data attributes for filtering $listContent .= '
'; if ( $event['thumbnail'] ) { $listContent .= '
'; $listContent .= '' . $event['thumbnail'] . ''; $listContent .= '
'; } $listContent .= '
'; foreach ( $event['times'] as $timeData ) { $time = $timeData['time']; $purchaseLink = $timeData['purchaseLink']; $timeObj = DateTime::createFromFormat( 'H:i', $time ); $formattedTime = $timeObj ? $timeObj->format( 'g:i A' ) : $time; $listContent .= '' . esc_html( $formattedTime ) . ''; } $listContent .= '
'; $listContent .= '
'; $listContent .= '
'; $listContent .= '

'; $listContent .= '' . esc_html( $event['title'] ) . ''; $listContent .= '

'; $listContent .= '

' . esc_html( $event['description'] ) . '

'; $listContent .= '
'; $listContent .= '
'; // .ats_timeline_event_content $listContent .= '
'; // .ats_timeline_event } $listContent .= '
'; // .ats_timeline_events $listContent .= '
'; // .ats_timeline_day } $listContent .= '
'; // .ats_event_timeline_container } else { $listContent .= '
No events found.
'; } $listContent .= '
'; // #ats_event_list_dateView $listContent .= '
'; return $listContent; } /* static function ats_shortcode_event_gridCB($atts) { // Set default shortcode attributes and merge with provided ones $atts = shortcode_atts([ 'posttype' => 'agile_post', // default to standard post type 'itemsWide' => 3, ], $atts, 'agiletix_event_list'); $postType = sanitize_key($atts['posttype']); $objPerRow = sanitize_key($atts['itemsWide']); $args = ['numberposts' => 99, 'post_type' => $postType, 'fields' => 'ids']; $posts = get_posts($args); $listContent = "
"; foreach ($posts as $post_id) { $title = get_the_title($post_id); $permalink = get_permalink($post_id); $thumb_id = get_post_thumbnail_id($post_id); $thumbnail = $thumb_id ? wp_get_attachment_image($thumb_id, 'thumbnail') : ''; $firstEndDate = get_post_meta($post_id, "ATS_firstEndDate", true); $date = new DateTime($firstEndDate); $readableDate = $date->format('F j, Y \a\t g:i A'); $listContent .= "
{$thumbnail}

{$title}


{$readableDate}
"; } $listContent .= "
"; return $listContent; }*/ /** * Shared markup for auto-scrolling event banners. */ private static function render_scrolling_banner_html( array $posts, $interval, $height, $banner_id_prefix, $date_meta_key, $legacy_prefix ) { self::enqueue_banner_assets(); $banner_id = $banner_id_prefix . uniqid(); $height_class = ( $height === 'auto' ) ? 'ats-banner-container--auto' : 'ats-banner-container--fixed'; $height_attr = ( $height === 'auto' ) ? '' : ' style="height:' . esc_attr( $height ) . '"'; $banner_html = '
'; $banner_html .= '
'; foreach ( $posts as $post ) { $post_id = $post->ID; $title = get_the_title( $post_id ); $permalink = get_permalink( $post_id ); $thumb_id = get_post_thumbnail_id( $post_id ); $formatted_date = ''; $date_value = get_post_meta( $post_id, $date_meta_key, true ); if ( ! empty( $date_value ) ) { try { $date_obj = new DateTime( $date_value ); $formatted_date = $date_obj->format( 'F j, Y' ); } catch ( Exception $e ) { $formatted_date = sanitize_text_field( $date_value ); } } $banner_html .= ''; if ( $thumb_id ) { $bg_image = wp_get_attachment_image_url( $thumb_id, 'full' ); $banner_html .= '
'; } $banner_html .= '
'; $banner_html .= '

' . esc_html( $title ) . '

'; if ( $formatted_date ) { $banner_html .= '
' . esc_html( $formatted_date ) . '
'; } $banner_html .= '
'; $banner_html .= '
'; } $banner_html .= '
'; if ( count( $posts ) > 1 ) { $banner_html .= ''; $banner_html .= ''; } $banner_html .= '
'; $banner_html .= '
'; foreach ( $posts as $index => $post ) { $active_class = $index === 0 ? ' active' : ''; $banner_html .= ''; } $banner_html .= '
'; $banner_html .= '
'; $banner_html .= '
'; return $banner_html; } /** * Coming Soon Banner Shortcode * Displays an auto-scrolling banner of coming soon events */ static function ats_shortcode_coming_soon_bannerCB( $atts ) { $postType = agile_tix_post_type::get_configured_post_type(); $atts = shortcode_atts( array( 'interval' => 8000, 'height' => 'auto', 'type' => '', ), $atts, 'agiletix_coming_soon_banner' ); $interval = absint( $atts['interval'] ); $height = sanitize_text_field( $atts['height'] ); $type = sanitize_text_field( $atts['type'] ); $args = array( 'post_type' => $postType, 'posts_per_page' => -1, 'meta_query' => array( array( 'key' => 'ATS_ComingSoonDate', 'compare' => 'EXISTS', ), ), 'orderby' => 'meta_value', 'meta_key' => 'ATS_ComingSoonDate', 'order' => 'ASC', ); $args = self::append_type_meta_query( $args, $type ); $posts = get_posts( $args ); if ( empty( $posts ) ) { return '
No coming soon events at this time.
'; } return self::render_scrolling_banner_html( $posts, $interval, $height, 'ats-coming-soon-banner-', 'ATS_ComingSoonDate', 'ats-coming-soon-banner' ); } /** * Now Showing Banner Shortcode * Displays an auto-scrolling banner of now showing events */ static function ats_shortcode_now_showing_bannerCB( $atts ) { $postType = agile_tix_post_type::get_configured_post_type(); $atts = shortcode_atts( array( 'interval' => 8000, 'height' => '500px', 'type' => '', ), $atts, 'agiletix_now_showing_banner' ); $interval = absint( $atts['interval'] ); $height = sanitize_text_field( $atts['height'] ); $type = sanitize_text_field( $atts['type'] ); $args = array( 'post_type' => $postType, 'posts_per_page' => -1, 'meta_query' => array( array( 'key' => 'ATS_ComingSoonDate', 'compare' => 'NOT EXISTS', ), ), 'orderby' => 'date', 'order' => 'DESC', ); $args = self::append_type_meta_query( $args, $type ); $posts = get_posts( $args ); if ( empty( $posts ) ) { return '
No now showing events at this time.
'; } return self::render_scrolling_banner_html( $posts, $interval, $height, 'ats-now-showing-banner-', 'ATS_firstEndDate', 'ats-now-showing-banner' ); } }