Support

Home Forums Event Espresso Premium How to get Event Topic from Event ID in Custom PHP plugin

How to get Event Topic from Event ID in Custom PHP plugin

Posted: June 20, 2023 at 9:27 am

Viewing 3 reply threads


pathwise

June 20, 2023 at 9:27 am

Looking for information on how I can load up an Event Espresso event object or just directly get the categories that have been assigned to an Event specified by its EVT_ID (post_id)


pathwise

June 20, 2023 at 9:31 am

Sorry let me try go clarify.

I am trying to get the list of categories assigned to events through a custom wordpress plugin. I have it setup so I have the post_id or EVT_ID of the event I am looking for, but I am not sure how to get the categories.


pathwise

June 20, 2023 at 9:35 am

Sorry, figured it out.

get_the_terms($post->ID, 'espresso_event_categories');


Tony

  • Support Staff

June 20, 2023 at 10:40 am

Hi there,

The above is correct and I’m glad you’ve found a solution.

To explain the code above a little, EE event categories are terms within custom taxonomy called espresso_event_categories.

If you haven’t doe so already I highly recommend taking a look at the documentation for our model system here:

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

For the above your single line is fine, using the models gives you quick and easy access to all of EE’s data (and related object data) and once you understand how they work you can grab pretty much any data you would need.

To give an example:

$event = EEH_Event_View::get_event($post_id);
if($event instanceof EE_Event) {
    $categories = $event->get_all_event_categories();
}

That’s not all that much different from what you have already, but as you need more info for the Event, that EE_Event object becomes much more useful to you.

Viewing 3 reply threads

The support post ‘How to get Event Topic from Event ID in Custom PHP plugin’ 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