Skip to content

Instantly share code, notes, and snippets.

@stephenharris
Last active August 29, 2015 14:05
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 stephenharris/e9f8537236f1987b0502 to your computer and use it in GitHub Desktop.
Save stephenharris/e9f8537236f1987b0502 to your computer and use it in GitHub Desktop.
An untested proof of concept solution to grouping events by day and ordering them by venue (upstairs & downstairs )
<?php
/**
* An untested proof of concept solution to grouping events by day and ordering them by venue
* (upstairs & downstairs )
* @see http://wp-event-organiser.com/forums/topic/returning-2-events-for-a-single-date-based-on-venue/
* @todo Change first three lines as appropriate
*/
$upstairs_id = 1; //Set to venue ID of upstairs venue
$downstairs_id = 2; //Set to venue ID of downstairs venue
$events = eo_get_events(array(...)); //Set this to the desired query
$num_events = count( $events );
$key = 0;
while( $key < $num_events ){
$event = $events[$key];
$next_event = isset( $events[$key + 1] ) ? $events[$key + 1] : false;
$date = eo_get_the_start( DATETIMEOBJ, $event->ID, null, $event->occurrence_id );
$key++; //Increment key
if( !$next_event ){
//No next event - just show this one, is it upstairs or downstairs?
$event_venue_id = eo_get_venue( $event->ID );
$upstairs_event = ( $event_venue_id == $upstairs_id ? $event : false );
$downstairs_event = ( $event_venue_id == $downstairs_id ? $event : false );
}elseif( eo_get_the_start( 'Y-m-d', $event->ID, null, $event->occurrence_id ) != eo_get_the_start( 'Y-m-d', $next_event->ID, null, $next_event->occurrence_id ) ){
//This event is on a different day to the next event, so ignore the next event for now
$upstairs_event = ( $event_venue_id == $upstairs_id ? $event : false );
$downstairs_event = ( $event_venue_id == $downstairs_id ? $event : false );
}else{
//This event is on the same day to the next event
$upstairs_event = ( $event_venue_id == $upstairs_id ? $next_event : $event );
$downstairs_event = ( $event_venue_id == $downstairs_id ? $event : $next_event );
//Increment key again has we're showing two events on this iteration.
$key++;
}
?>
<div>
<h3> <?php echo 'Events on date '.$date->format('jS F Y' );?> </h3>
<!-- Upstairs -->
<div class="upstairs">
<?php if( $upstairs_event ): ?>
<?php echo get_the_title( $upstairs_event->ID ); ?>
<?php endif; ?>
</div>
<div class="downstairs">
<?php if( $downstairs_event ): ?>
<?php echo get_the_title( $downstairs_event->ID ); ?>
<?php endif; ?>
</div>
</div>
<?php
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment