tribe_get_events combine same day events

I am creating a “now playing” feed for a cinema website. Each “event” is a film shown at the cinema. Each showing is setup as an event series, in Tribe Events Calendar Pro.

I have a custom plugin, which displays a list of all events for the next 7 days. It checks the date, and loops through displaying 7 days of events separately.

This works great, until I have a recurring event with 2 or more start times in the same day. What I want to do, is somehow check if the event has multiple start times in the same day. If yes, then show the event ONCE in the day, but display both start times underneath.

For example: Film 1, recurring event. Event starts:

11th Feb 18:00
11th Feb 19:00
11th Feb 22:00
12th Feb 10:00

Currently, it displays the same event 3 times under 11th Feb, separately, and then once on 12th Feb. What I want it to do is display the event ONCE on 11th Feb, but with the 3 start-times underneath, and then again on the 12th as a separate listing.

Here’s the code:

foreach( range(0,6) as $cnt ){
echo strtoupper( date(‘D d’,strtotime( “today + $cnt day”) ) ) . ” / “;
$start_date = strtoupper( date(‘Y-m-d’,strtotime( “today + $cnt day”) ) ) . “00:01”;
$end_date = strtoupper( date(‘Y-m-d’,strtotime( “today + $cnt day”) ) ) . “23:59″;
$args = array(
‘start_date’ => $start_date,
‘end_date’ => $end_date
);
$events = tribe_get_events( $args );
echo ‘<div class=”flex”>’;
foreach ( $events as $event ) { global $post; ?>
<div class=”one-fourth”>
<?php echo tribe_event_featured_image( $event->ID, ‘medium’ ); ?>
<h4><?php echo $event->post_title; ?></h4>
<div class=”start-times”>
<?php echo tribe_get_start_date($event, false, $format= ‘h:i A’);?>
</div>
</div>
<?php }
echo ‘</div>’;
}

Read more here:: tribe_get_events combine same day events

Leave a Reply

Your email address will not be published. Required fields are marked *