Posted: August 14, 2014 at 4:16 pm
|
I need to display all events that are associated with a venue. What is the best way to do this? Related to this question, is there a way to get an Event object by ID (which would include all event details)? My current solution uses a secondary advanced custom field (ACF) to build a relationship between the Event and Venue CPT. I use a reverse relationship to create an array of Events and then a FOREACH statement to select only the Events which are associated with the current page ID (the venue page ID). This solution works great for getting the basic CPT information from the events associated with the Venue. There are two issues with this method. 1) I have to have a duplicate Venue field on the Event edit page. 2) I can’t get any other information except standard WP info about the event. I need Event date, price, availability, etc. Because the above solution doesn’t use Wp_Query I can’t use the template tags. I could use all of my existing code if there was a way to query events based on ID and get the full Event object returned. Alternatively, is there a way to load the Event helper onto the single Venue page outside the WP Loop? You can see the dev page where this particular code is being used here (it’s in active development so it may change and/or be broken when you visit). The following code is listed after the primary Loop for that page which displays the Venue details.
|
|
How can I list the events associated with a venue, displayed on the single venue page, without a shortcode? |
|
In the same way that you grabbed the EE_Event object in your other post, you’ll need to grab the EE_Venue object, then use it’s events method: http://code.eventespresso.com/classes/EE_Venue.html#method_events. Here’s the get_venue method: http://code.eventespresso.com/classes/EEH_Venue_View.html#method_get_venue. Note that you may need to go into the code and change that method to public. (it’s been fixed in 4.4) |
|
Thanks Sidney, it sounds like that will work. Can you give me an example of how I would use that? |
|
To be more clear, how would I adjust the following code so it does what you recommend?
Thanks so much! |
|
I got this working with your recommendation. Thank you! On the single venue page I already had the venue object so I just called the events() method on it to display all events associated with that venue. It works great except… The events list is not sorted by start date. What’s the best way to do that? You can see this in action here. |
Hi James, They look to be sorted by ascending date when I view the page. Did you get this worked out? |
|
|
Thanks for taking a look, Josh. I was able to get it working with the following code:
|
|
Hi, Thanks for sharing the code! |
|
Turns out this broke with multiple events. Is there a $query_params I can send to the events() method that will sort them by start date? |
|
It appears that the Primary Datetime method returns null when multiple events are called.
You can see the var_dump( $venues_events ) here. |
|
Alright, I found a solution. It’s dirty but I have to take this site live in a couple days so it’ll have to work until I hear back from support. It looks like the error was taking place because the Instead of trying to change the query I just use if statements to ignore the trashed events. However, it hinges on the I modified the above code to only call the
And then in my loop I only display events if their status is also “publish”.
None of this would be necessary if two things were assumed when I call the I think this should be default behavior. |
Hi James, I think I follow what you’re trying to. This will also do the job: $events = EEM_Event::instance()->get_all(array( array( 'Venue.VNU_ID'=>$post->ID ), 'order_by'=>'Datetime.DTT_EVT_start','order'=>'DESC' ) ); foreach($events as $event){ // loop here } |
|
The support post ‘Display all Events associated with a Venue – Displayed on Single Venue Page’ is closed to new replies.
Have a question about this support post? Create a new support post in our support forums and include a link to this existing support post so we can help you.