Support

Home Forums Event Espresso Premium espresso_venue_address not working

espresso_venue_address not working

Posted: June 13, 2016 at 9:39 am


Matt Fifer

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:

$event_address = espresso_venue_address( 'inline', $e->ID, FALSE );// (and TRUE);
$event_address = EEH_Venue_View::venue_address( 'inline', $e->ID );// alternative

Just getting a blank, empty string.
if(function_exists('espress_venue_address')); returns true

We’re using EE4 version 4.8.43.p

You can see the loop in action here: https://supplier.community/events/

Thanks in advance!


Josh

  • Support Staff

June 13, 2016 at 12:41 pm

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:

<?php $VNU_ID = espresso_venue_id( $post->ID ); ?>


Matt Fifer

June 13, 2016 at 12:57 pm

Josh,
Thanks for fast response! I’ve updated my code accordingly:

$VNU_ID = espresso_venue_id( $e->ID );
$event_address = espresso_venue_address( 'inline', $VNU_ID, FALSE );

$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?


Tony

  • Support Staff

June 14, 2016 at 3:21 am

Nice job with the event list πŸ™‚

You can use the EE Models to pull in events:

https://github.com/eventespresso/event-espresso-core/blob/master/docs/G–Model-System/model-querying.md

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 = $post->EE_event

$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.


Matt Fifer

June 14, 2016 at 10:45 am

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:

$newEvents = EEM_Event::instance()->get_upcoming_events();
foreach($newEvents as $nE){
	$eventID = $nE->ID();
	echo '<p>Event ID: '.$eventID.'</p>';
	echo '<p>Event Name: '.$nE->name().'</p>';
	echo '<p>Event Phone: '.$nE->phone().'</p>';
	echo '<p>Event Venue ID: '.espresso_venue_id($eventID).'</p>';
	
}

The first result returns:

<p>Event ID: 612</p>
<p>Event Name: CPG Innovators Conference</p>
<p>Event Phone: 479-426-1216</p>
<p>Event Venue ID: 0</p>

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…


Matt Fifer

June 14, 2016 at 10:52 am

Here’s the full result of the loop to demonstrate each event is getting its own $eventID in the foreach loop:

<p>Event ID: 612</p>
<p>Event Name: CPG Innovators Conference</p>
<p>Event Phone: 479-426-1216</p>
<p>Event Venue ID: 0</p>

<p>Event ID: 636</p>
<p>Event Name: WalStreet Speaker Series - Tony Rogers</p>
<p>Event Phone: 479-273-2841</p>
<p>Event Venue ID: 0</p>

<p>Event ID: 648</p>
<p>Event Name: Omni Shopper 2016</p>
<p>Event Phone: 888-670-8200</p>
<p>Event Venue ID: 0</p>

<p>Event ID: 660</p>
<p>Event Name: Future Stores</p>
<p>Event Phone: 1-888-482-6012</p>
<p>Event Venue ID: 0</p>

<p>Event ID: 662</p>
<p>Event Name: eMetrics Summit</p>
<p>Event Phone: 1-508-208-8264</p>
<p>Event Venue ID: 0</p>

<p>Event ID: 664</p>
<p>Event Name: FMI Connect</p>
<p>Event Phone: 708.344.1639</p>
<p>Event Venue ID: 0</p>

<p>Event ID: 668</p>
<p>Event Name: Consumer 360</p>
<p>Event Phone: 1.800.864.1224</p>

<p>Event Venue ID: 0</p>
<p>Event ID: 674</p>
<p>Event Name: Digital Experience Workshop</p>
<p>Event Phone: 1-800-673-4692</p>
<p>Event Venue ID: 0</p>

<p>Event ID: 682</p>
<p>Event Name: NRF Tech</p>
<p>Event Phone: 1-800-673-4692</p>
<p>Event Venue ID: 0</p>

<p>Event ID: 685</p>
<p>Event Name: Global Sustainability Summit</p>
<p>Event Phone: </p>
<p>Event Venue ID: 0</p>

<p>Event ID: 687</p>
<p>Event Name: Retail 360 Summit</p>
<p>Event Phone: 201-855-7621</p>
<p>Event Venue ID: 0</p>

<p>Event ID: 689</p>
<p>Event Name: International Retail Design Conference</p>
<p>Event Phone: 513-263-9307</p>
<p>Event Venue ID: 0</p>

<p>Event ID: 691</p>
<p>Event Name: Retail's Digital Summit</p>
<p>Event Phone: 800-974-9069</p>
<p>Event Venue ID: 0</p>

<p>Event ID: 693</p>
<p>Event Name: NEW Leadership Summit</p>
<p>Event Phone: </p>
<p>Event Venue ID: 0</p>


Tony

  • Support Staff

June 14, 2016 at 12:18 pm

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 '

Event Venue ID: '. $venue instanceof EE_Venue ? $venue->ID() : 0 . '

';


Matt Fifer

June 14, 2016 at 4:35 pm

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:

$venues = $e->venues();
if(!empty($venues)){
	$venue 			= reset($venues);
	$venue_name 	= '<strong>'.$venue->name().' </strong><br />';
	$venue_address1 = $venue->address().', ';
	$venue_address2 = $venue->address2().', ';
	if($venue_address2 == ', '){
		$venue_address2 = '';
	}
	$venue_city 	= $venue->city().', ';
	$venue_state 	= $venue->state();
	$event_address 	= $venue_name.$venue_address1.$venue_address2.$venue_city.$venue_state;
} else {
	$venue = '';
	$event_address = '';
}

Thanks much for your help! Would have burned days without you πŸ™‚


Tony

  • Support Staff

June 15, 2016 at 8:18 am

espresso_venue_address(), espresso_venue_id() and EEH_Venue_View::venue_address() all use the same internal function EEH_Venue_View::get_venue( $VNU_ID ); to get the venue so if one breaks its likely the others will too.

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.

Event Espresso