Support

Home Forums Event Espresso Premium How to get venue information in upcoming events widget

How to get venue information in upcoming events widget

Posted: September 24, 2018 at 9:37 am


qianglu

September 24, 2018 at 9:37 am

I am customizing upcoming events widget to display venue information. Tried to follow https://eventespresso.com/topic/display-event-venue-details-as-a-sidebar/
$VNU_ID = espresso_venue_id( $event->ID() ); //Get venue id
$venue_description = espresso_venue_description( $VNU_ID, TRUE ); //Venue description
$venue_excerpt = espresso_venue_excerpt( $VNU_ID, TRUE );
//Venue short description
$address = espresso_venue_address(‘multiline’, $VNU_ID, TRUE );

But doesn’t work. Could you please help me?


Josh

  • Support Staff

September 24, 2018 at 9:51 am

One issue with the code is the second parameter in each of those 3 template tags, is for controlling how the venue information is output (in other words, check the source in public/template_tags.php if you’re not sure what you’re setting “true” for)

In this case, you’re setting those to TRUE and setting a variable. TRUE means you want to echo, so you’ll either set those to false, then echo out the variables later. Or just remove the variable assignments e.g.

$VNU_ID = espresso_venue_id( $event->ID() ); //Get venue id
espresso_venue_description( $VNU_ID, TRUE ); //Venue description
espresso_venue_excerpt( $VNU_ID, TRUE );
//Venue short description
espresso_venue_address('multiline', $VNU_ID, TRUE );


qianglu

September 24, 2018 at 12:22 pm

I correct the mistakes, however, still cannot get the venue id by using espresso_venue_id( $event->ID() ). The $event->ID() did have the right id of the event. However from the event to the venue, it just get an id of 0.


Josh

  • Support Staff

September 24, 2018 at 12:33 pm

I can’t tell from what you’ve posted if you even have access to the $event object at that point. Maybe you can post a gist or a pastebin that includes the full code in context.


qianglu

September 24, 2018 at 1:01 pm

Thank you Josh,
Here is the gist link,
https://gist.github.com/qianglu/2c45d8a2811d72ce5f11a81de4923791

From line 498 to 516, I can echo the event id, however it doesn’t give me the venue id.


Josh

  • Support Staff

September 24, 2018 at 1:12 pm

The reason being is you’ve made the ID into a string:

$VNU_ID = espresso_venue_id( "$id" ); //Get venue id

The correct data type there for the ID parameter is an integer. In other words, you need to remove the double quotes there. Also, please note the $id variable is already set on line 430,
https://gist.github.com/qianglu/2c45d8a2811d72ce5f11a81de4923791#file-sample-functionality-plugin-php-L430
So you do not need to set that variable again.


qianglu

September 24, 2018 at 3:25 pm

Josh, even the double quotes are removed, the error is still there.
It showes: id=13139VNU_ID=0venue_description=venue_excerpt=address=


qianglu

September 24, 2018 at 4:04 pm

when I look into the codes, espresso_venue_id() using get_venue($eventid), however, the actual get_venue function require venue id.


Tony

  • Support Staff

September 25, 2018 at 10:24 am

get_venue() jumps through multiple hoops to try and pull an EE venue object any way it can depending on the ID passed to it, if the current post object is an EE event or EE venue and so on. If it can’t find an EE Venue object by the end of it, it pulls one from the database directly using the ID passed to the function.

You could just pull the venue object directly yourself if you know the ID:

$venue = EEM_Venue::instance()->get_one_by_ID($VNU_ID);
if( $venue instanceof EE_Venue ) { // Do something }

Or you can pull the venue directly from the event object if you have one (you do):

$venue = $event->EE_Venue;
if( $venue instanceof EE_Venue ) { // Do something }

If $VNU_ID = espresso_venue_id( $event->ID() ); is returning 0 then there is something more going on as if the venue is attached to the event then the above (if it can’t find a venue any other way) should do exactly the same as above.


Josh

  • Support Staff

September 25, 2018 at 10:32 am

It actually depends on the context of the post type the code is running from. Instead of using the code from the other forum post, which was likely intended to be used on an event post type, what you could do is get the venue ID from the event object itself. e.g.

$VNU_ID = null;
$venues = array();
$venue = null;
$venues = $event->venues();
$venue = reset( $venues );
if ( $venue instanceof EE_Venue ) {
    $VNU_ID = $venue->ID();
    espresso_venue_description( $VNU_ID, TRUE ); 
    espresso_venue_excerpt( $VNU_ID, TRUE );
    espresso_venue_address('multiline', $VNU_ID, TRUE );
}

The support post ‘How to get venue information in upcoming events widget’ 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.

Support forum for Event Espresso 3 and Event Espresso 4.
Documentation for EE3 and EE4
Documentation for Event Espresso 3

Documentation for Event Espresso 4

Status: closed

Updated by  Josh 1 year ago ago

Topic Tags

Tagged: ,

Notifications

This topic is: not resolved
Do NOT follow this link or you will be banned from the site!