Support

Home Forums Event Espresso Premium Does Post Information Have Custom Fields

Does Post Information Have Custom Fields

Posted: July 18, 2022 at 7:45 pm

Viewing 3 reply threads


ArtontheTown

July 18, 2022 at 7:45 pm

Hey Guys!

I am attempting to use Event Espresso 4 with Beaver Builder and Beaver Themer.

I’m trying to create a layout for the events using Beaver Themer, and that tool allows me to specifically target custom fields of the post and display them on the frontend, so all events can (hypothetically) share the same themer layout with an updated design.

I’ve tried to guess at what the custom field meta key would be for the datetimes and venue and other things like that, but in all of my testing I have not been able to find the custom field meta for the event fields.

Can you please let me know the custom field meta keys for the Event Espresso event fields, or show me where in the documentation that is?

Thanks so much!


Tony

  • Support Staff

July 20, 2022 at 4:29 am

Hi there,

We use a hybrid approach in that we do use custom post types but then all of the related data for that post is stored in custom tables rather than WP custom fields.

We then hook into the_content and inject the details into the post content on the fly, or it’s also possible to use template files to call specific functions to display the data (as it will pull in the data itself not using custom fields).

So the reason you can’t guess the custom field meta keys is there are none 🙂

Does Beaver Theme allow you to call custom functions rather than custom fields?


ArtontheTown

July 21, 2022 at 9:05 pm

Good Evening Tony,

That makes a ton of sense, thank you for the information!

I’m not *sure* if I can directly call the functions rather than fields, but it’s certainly worth a shot.

Can you please send over an example of how you would call the function for a datetime. (Or just the starting datetime if we need to be super specific?)

I’ll take a crack at it and get the Beaver Builder support team involved.

Thanks so much!

-Simon


Tony

  • Support Staff

July 22, 2022 at 4:10 am

Ok, so there’s a few ways of getting the EE data, depending on what you have already and from ‘where’ (which will make sense in a little).

The quickest example if can give you to answer your question is to take a look at the template examples within EE itself:

https://github.com/eventespresso/event-espresso-core/tree/master/public/Espresso_Arabica_2014

content-espresso_events-datetimes.php is a template file called to display the datetimes within the EE events:

https://github.com/eventespresso/event-espresso-core/blob/master/public/Espresso_Arabica_2014/content-espresso_events-datetimes.php

That’s calling a template tag espresso_list_of_event_dates and passing the post ID, if we look at that function HERE you can see how its using some of our helper functions, which then uses the model system to get the data.

It depends on how much control you want ver the specific output what you need to do but looking over how that template tag works should give you more of an idea.

This bit is going to get a bit deeper, I don’t know if you are comfortable with PHP but here are some more advanced details.

When using Event Espresso the ‘best’ way to get access to any of the data you need is to understand our model system:

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

Once you understand the model system getting the data you need becomes relatively simple, how you get it changes depending on what you have already and what you need. To give you a quick example, you asked for details on how to get to a DateTime, but would you have something to specific call a DateTime already? Probably not.

A simple example of getting a DateTime when you have that Datetime’s ID (which you likely won’t on its own usually) is:


$DTT_ID = 111;
$datetime = EEM_Datetime::instance()->get_one_by_ID($DTT_ID);

Now $datetime is an EE_Datetime object which has all kinds of various method available to output details… but you had the ID there and that’s not likely to be something you happen to have.

Datetimes are related to events (the post) so you’ll likely have the WP post or an EE_Event object (which we automatically inject into EE cpt’s) and you can pull the datetimes from that easily. Let’s go with an example, again more than one way of doing this but I’ll give you one using our helper functions.

If you have the global post and it’s the post related to an EE event you can do:

$event = EEH_Event_View::get_event($post);
(In this case EE checks if the post you passed is an EE post type and then returns the EE_Event object for it, also caching it for future use in the request)

or

$event = EEH_Event_View::get_event($post->ID);
(In this case you’ve passed a specific ID… it may be the current post ID or another, say you know the specific event ID you’d use it here, EE then pulls in the EE_Event for that ID, caches it and returns)

or even:

$event = EEH_Event_View::get_event();
(EE will use the global post to see if it’s an EE_Event, cache and return)

Then always confirm you have what you expect before using it, so in this case $event should be an instance of EE event, lets check:

if (! $event instanceof EE_Event) {
    return;
}

You want the datetimes for that event so you can do something like:

$datetimes = $event->datetimes_ordered($show_expired = false, $show_deleted = false, $limit = null);

Now datetimes will be an array of EE_Datetimes (even if its just one) or an an empty array if none are to be returned.

Now again you have access to the datetimes related to a specific event, each of those have multiple methods to output whatever you need for that DateTime… and even pull in related objects for that DateTime, like its related tickets.

As you start to work through the models you start to see how it makes it much easier to pull in related data from what you have/need than just starting from a post/ID and then using custom fields or functions to pull specific data.

Viewing 3 reply threads

The support post ‘Does Post Information Have Custom Fields’ 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