Support

Home Forums Event Espresso Premium Need a shortcode to display the event city

Need a shortcode to display the event city

Posted: October 1, 2021 at 3:32 pm


ICLE

October 1, 2021 at 3:32 pm

Trying to display the venue name from a snippet in a shortcode like this:
[yourshortcode YourParam=”{post.ID}”]
This is so I can populate a column of data in my ninjatables report.
IMAGE

Been running in circles on this one for a while. Can you suggest anything?


Tony

  • Support Staff

October 4, 2021 at 8:36 am

Hi there,

We don’t currently have a shortcode that can be used to display details like this from the post ID, assuming that’s an espresso_events post (meaning an EE Event post) ID?

If you have the Post ID for an EE event then you can create your own shortcode to pull in whatever details you need from there using our model system.

For example, to pull the Venue from an EE event in shortcode you could do something like this:

https://gist.github.com/Pebblo/b2a0c9e1bf17b78f04e378b92468daa2

That adds a [EE_CUSTOM_VALUE_SHORTCODE event_id=XXX] shortcode to your site, pass it an event ID and it will return the name of the venue assigned to it if there is one. You can also add additional checks to that function for value different values to be returned depending on what you need.

Note the above snippet is not an official product of Event Espresso and should be considered untested and unsupported.


ICLE

October 7, 2021 at 9:48 am

That worked marvelously! Plunked the code from the gist into the child theme functions.php.
The exact syntax for the shortcode in NinjaTables is:
[EE_CUSTOM_VALUE_SHORTCODE event_id='{post.ID}']

I want to do something similar to expose the data from wp_esp_datetime.DTT_EVT_START so I can have a start date column as well. I totally mangled that code you put together, thought you might be a sport and point me in the right direction on the date start. Thanks.


Tony

  • Support Staff

October 13, 2021 at 11:03 am

I’ve updated my gist to include an example of pulling the primary datetime from an event and returning the start date from that:

https://gist.github.com/Pebblo/b2a0c9e1bf17b78f04e378b92468daa2

A single event can have many datetimes, so you’ll likely need to alter the above to suit your specific event setups.


ICLE

October 13, 2021 at 11:24 am

Thanks! Those examples are very enlightening!


Tony

  • Support Staff

October 13, 2021 at 11:39 am

Our model system makes pulling in various data from EE objects (and their related objects) really straight forward which is why I always recommend learning at least the basics of using them 🙂

We have documentation for that system here:

https://github.com/eventespresso/event-espresso-core/tree/master/docs/G–Model-System

I recommend using something like Kint:

https://wordpress.org/plugins/kint-debugger/

Wrap an EE model object in d(); (Example: d($event);) with the above plugin active and you’ll get a nice easy to follow output that shows you all of the methods available on that object to use.

You must be logged in to reply to this support post. Sign In or Register for an Account

Event Espresso