Posted: June 13, 2016 at 9:39 am
|
I’ve got a custom archive-espresso_events.php file that is working great except when I try to display the event venue. I’ve tried where $e->ID is equivalent to your $VNU_ID in your documentation:
Just getting a blank, empty string. We’re using EE4 version 4.8.43.p You can see the loop in action here: https://supplier.community/events/ Thanks in advance! |
Hi Matt, May I ask where you saw that $e->ID is equivalent to $VNU_ID in the documentation. I can’t say for sure without seeing your code in context, but the solution may be to get the correct venue ID, which you can do if you have the event’s post object, with:
|
|
|
Josh,
$e->ID is the post ID from a foreach loop of posts with the post_type of ‘esspresso_events’ and a post_status of ‘publish’. Is there a better function for getting an object/array of events? |
Nice job with the event list π You can use the EE Models to pull in events: So something like this: $events = $events = EEM_Event::instance()->get_upcoming_events(); foreach($events as $event) { //some output echo $event->name(); } Should pull in an array of EE event objects for upcoming events. You can also pass values to alter the query, take a look within the above documentation for more examples. However if you are using archive-espresso_events.php the main query should have the EE_Event object within each $post.
$event is now the same Event object that you would have gotten within the foreach loop above. In other words it seems like your running a custom loop within archive-espresso_events.php to pull in all of the EE events, even though by default the main query includes the EE events. So you may be running an additional to pull the info in without needing to, we can’t be sure from your code above, but just something to be aware of. |
|
|
Great info! I updated the archive-espresso_event.php to use this model. BUT, I’m still getting a ‘0’ for the Venue ID. Here’s a code snippet:
The first result returns:
All the events in this loop have a Venue ID of 0. In the Espresso Events Admin panel, the events all have a different venue and display properly in the Admin events view as well as on the individual event edit pages. I think we’re close, just missing something… |
|
Here’s the full result of the loop to demonstrate each event is getting its own $eventID in the foreach loop:
|
I think its because your running a custom loop and its confusing the function as the global $post object is an EE_Event. You can pull the events for each of your events using the models: //Pull in all EE Venues assigned to the event. $venues = $nE->venues(); //Check you have at least one venue. if( !empty($venues) ) { //Set $venue to the first venue assigned to the event $venue = reset($venues); } else { //No Venues, set $venue to NULL. $venue = NULL; } //Check we have an EE_Venue object and output the ID, otherwise output 0 echo ' |
|
|
That got me close enough that I could finish out the functionality. I could not get the espresso_venue_address() functionality to work within my loop. I even went straight to the core class EEH_Venue_View::venue_address( ‘inline’, $VNU_ID, true, true ); to no avail. BUT, the snippet above helped me carve out the fields I needed. Final, successful code looks like this:
Thanks much for your help! Would have burned days without you π |
I’m going to investigate this a little further with the developers but I’m glad you’ve got a working solution π |
|
The support post ‘espresso_venue_address not working’ 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.