Returning 2 events for a single date based on venue
WordPress Event Management, Calendars & Registration › Forums › General Question › Returning 2 events for a single date based on venue
This topic contains 18 replies, has 2 voices, and was last updated by Colin Frangos 10 years, 6 months ago.
-
AuthorPosts
-
August 8, 2014 at 4:06 am #12005
I’m putting together a site for a local club, with this plug-in as the backbone. The issue is that it’s a 2 story venue, with some events upstairs and some downstairs. They want the presentation of each date’s events to follow that logic and have upstairs events listed above the downstairs events.
I threw together a quickie site for them that gets the information that they need available out there in the short term, which can be viewed here:
http://www.thenightlightoakland.com/There won’t always be 2 things going on, but usually there will be. When there’s nothing in one venue, I need to return a “No event tonight” message.
Currently, I’m using a wp_query loop with these basic arguments:
$calendar_args = array( 'post_type' => 'event', 'event_end_after'=>'now', 'posts_per_page' => 50 );
… and just filling in the information for the downstairs event with a custom field based on the date of the upstairs event. Dirt simple, but a crude placeholder (their old site went down so we needed something immediately). Since the downstairs has mostly recurring events, being able to program them separately would be a huge time saver.
So my question is: how do I get 2 separate events to show up for each date (when there are 2) and to position and style themselves based on venue and not start time?
My thinking is that treating the Upstairs and Downstairs as separate venues might allow me to do this with a venue_query, and if I can cause them to sort by distance within each date (let’s say that I cheat and make the address of the downstairs slightly farther away from the upstairs) that would give me what I want. Something like this example from the codex:
$venue_query = array( 'proximity' => array( 'center' => eo_remote_geocode( "Windsor [castle]" ), 'distance' => 10, 'unit' => 'miles', 'compare' => '<=' ), ); $events = eo_get_events( array( 'event_start_after' => 'now', 'venue_query' => $venue_query, ));
Would that return the results as expected?
Otherwise, it seems like I’m looking at one of 2 messy options:
- Use CSS and absolute positioning based on category to generate
layouts - Use an if/then to spit out one of 3 different layouts (events<br />
upstairs and downstairs, event upstairs but not downstairs, and<br />
downstairs but not upstairs) based on venue or category
Yuck.
Assuming we can make a loop that returns content the way we want it they’ll be buying a Pro version tomorrow. Maybe even if it can’t – They’re interested in selling their own tickets, and EO is the best answer to their needs.
Colin Frangos
August 8, 2014 at 11:58 am #12012Hi Colin,
I would definitely create two separate venues (let’s call them U (upstairs) and D (downstairs), for now). Then you may well have event dates U8Aug, U9Aug, U12Aug and event dates D8Aug, D9Aug, D10Aug.
A straightforward query may give you
- U8Aug
- D8Aug
- D9Aug
- U9Aug
- D10Aug
- U12Aug
So the date/times are in the correct order, but we cannot assume the that one venue is always before the other when the dates match.
Basically we’re grouping by date, but we may need to look ahead so that we can group them in the “correct” order (upstairs, then downstairs).
In this gist I’ve given an example of how to do this with
eo_get_events()
and awhile
loop. It’s untested and also requires the first three lines (and the mark-up at the bottom) to be edited. It makes some assumptions:- There are at most 2 events on any given day
- Those two events are in different venues (upstairs or downstairs).
Note it is achieved with
eo_get_events()
rather thanWP_Query()
. This was largely out of simplicity, but you should note that youre’ not “in The Loop” which means functions likethe_content()
or thethe_excerpt()
won’t work. Though I’ve written this article on how to get round situations like that.Stephen Harris
August 8, 2014 at 12:03 pm #12013Just a brief explanation of that gist.
We loop through the events, but actually we’re iterating on the date. So each iteration will print the mark-up for one date. We do this by looking ahead, and if the next event is on the same date as the current event we include it in the mark-up. Otherwise, we ignore it and deal with it on the next iteration.
Where the event and the next event are on the same date, we “jump forward” so we don’t encounter that event again in the next iteration.
In all cases we assign events (or
false
, if they don’t exist) to the$upstairs_event
and$downstairs_event
variables, and use that to determine the mark-up.Stephen Harris
August 8, 2014 at 6:08 pm #12020Brilliant. I will probably have some questions once I get this rolling, but this looks like exactly what I’m looking for.
Colin Frangos
August 11, 2014 at 8:31 pm #12058I think I’m missing something.
I updated the 3 lines from the github code you posted and added it to an install on my test site:
http://colinfrangos.com/night-light-beta/
I also added a note to identify which div is spitting out (cleverly titled “upstairs div” and “downstairs div”).The code looks like this:
$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( 'post_type' => 'event', 'event_end_after'=>'now', 'posts_per_page' => 50 ));
Otherwise, exactly like yours. I couldn’t find where the venue ID is established, but they are 1 and 2 in the list. I also tried replacing them with the slugs, and it didn’t change anything, so perhaps that’s where I’m making the mistake.
Colin Frangos
August 11, 2014 at 8:39 pm #12059Also worth noting that there are events schedule upstairs on the 14th and 15th, which aren’t returning anything.
Colin Frangos
August 11, 2014 at 10:01 pm #12060If you haven’t been able to find the venue IDs then you can probably expect the events not to display correctly (or some at all). I’ve also spotted an error which I’ve since corrected.
Finding the venue ID is a little tricky. Instead you could replace
$event_venue_id = eo_get_venue( $event->ID );
with
$event_venue_slug = eo_get_venue_slug( $event->ID );
and compare venues by slug instead.
Stephen Harris
August 11, 2014 at 10:53 pm #12064Seems to be ordering them by time underneath the date:
http://colinfrangos.com/night-light-beta/23rd of August has a events with their start time assigned.
I’m assuming I should replace each instance of $event_venue_id with the call for the slug – correct? Since there will only ever be 2 venues at this club, I’m assuming I could replace
$upstairs_event = ( $event_venue_id == $upstairs_id ? $event : false ); $downstairs_event = ( $event_venue_id == $downstairs_id ? $event : false );
with
$upstairs_event = ( $event_venue_slug=='upstairs' ? $event : false ); $downstairs_event = ( $event_venue_slug=='downstairs'? $event : false );
Or am I missing something?
Out of curiosity, how would I find the venue ID? It’s not in the xml export or the ics export.
Colin Frangos
August 11, 2014 at 10:59 pm #12065Yes, it will order by time. So the
while
loop looks ahead to re-order the events (if necessary) if there are two events on the same day.I’m assuming I should replace each instance of $event_venue_id with the call for the slug – correct?
Yes. And also you would make the changes you’ve described.
The venue ID can be found in the mark-up of the venue’s page or in the mark-up of the venue admin page. It’s fairly obscure though. Venue slug is better since if you’re dealing with a production and test site, IDs may change, but the slug will generally not.
Stephen Harris
August 11, 2014 at 11:01 pm #12066Also you’ll want to replace
$upstairs_event = ( $event_venue_id == $upstairs_id ? $next_event : $event ); $downstairs_event = ( $event_venue_id == $downstairs_id ? $event : $next_event );
with
$upstairs_event = ( $event_venue_slug == 'upstairs' ? $next_event : $event ); $downstairs_event = ( $event_venue_slug == 'downstairs' ? $event : $next_event );
If using the slug rather than ID.
Stephen Harris
August 11, 2014 at 11:29 pm #12067Almost there. When there are 2 events, they’re both returning the downstairs event. I think the problem is here:
//This event is on the same day to the next event $event_venue_slug = eo_get_venue_slug( $event->ID ); $upstairs_event = ( $event_venue_slug == 'upstairs' ? $next_event : $event ); $downstairs_event = ( $event_venue_slug == 'downstairs' ? $event : $next_event );
I replaced that with:
$event_venue_slug = eo_get_venue_slug( $event->ID ); $upstairs_event = ( $event_venue_slug == 'upstairs' ? $event : $event ); $downstairs_event = ( $event_venue_slug == 'downstairs' ? $next_event : $next_event );
Which returns both events, but returns them chronologically, not by venue (the first event appears in the Upstairs div, second in the Downstairs).
Thanks in advance – this is much farther than my php knowledge stretches, and I appreciate the help.
Colin Frangos
August 11, 2014 at 11:54 pm #12068This seems to be returning the proper results in the proper order:
//This event is on the same day to the next event $event_venue_slug = eo_get_venue_slug( $event->ID ); $upstairs_event = ( $event_venue_slug == 'upstairs' ? $event : $next_event ); $downstairs_event = ( $event_venue_slug == 'downstairs' ? $event : $next_event );
Colin Frangos
August 12, 2014 at 1:21 am #12069Ah yes, I see where the mistake was now. Your last post should be correct.
Stephen Harris
August 12, 2014 at 3:43 am #12070I think I mostly have the hang of getting post content by ID, but I’ve hit one other stumbling block:
$large_image_url = wp_get_attachment_image_src( get_post_thumbnail_id(), 'large'); echo '<figure class="venue-flyer">'; the_post_thumbnail('home'); echo '</figure>';
I’ve been using this variable to return an image I can lightbox. Perhaps it’s just because I’m at the end of a long day, but I’m not seeing how to do this by calling
$upstairs_event->ID
.Colin Frangos
August 15, 2014 at 1:55 am #12128I realize this is outside of the scope of your support here, but I’m still having an issue with this one element:
$large_image_url = wp_get_attachment_image_src( get_post_thumbnail_id(), ‘large’);I need to be able to lighbox the images, which means returning the link to the large image. Any help you can offer?
Colin Frangos
- Use CSS and absolute positioning based on category to generate
-
AuthorPosts