Support

Home Forums Event Espresso Premium Getting all the event metas like Location,approved registration etc.

Getting all the event metas like Location,approved registration etc.

Posted: October 14, 2014 at 10:47 pm


Ray

October 14, 2014 at 10:47 pm

I’ve been trying to have access to event meta for an event like its venue, number of approved registration, pending registration, unapproved registration for an event in my custom page template within a custom WP_Query loop but as of today I’m unable to get any of the meta from default WordPress get_post_meta() function,hence I looked into the post meta table of the database there were no such event related post metas in the table, so I looked into the plugin files and found that all the variables are protected or private type and cannot be accessed out side of the class so I tried to use public method to access those variable and was able to get some of the fields like ‘Event Time’,’Event Name’,’Event Author’,’Total Tickets Sale’ through the public methods, but some of the public method don’t even return any data without any errors. So if you please kindly guide me through the process of getting those data it will be very helpful to me. I can give you my code if you want to see what am I doing wrong. Thank you in advance.


Lorenzo Orlando Caum

  • Support Staff

October 15, 2014 at 9:06 am

Hi,

Could you take a look at this resource?

http://developer.eventespresso.com/docs/ee-model-objects-and-custom-post-types/


Lorenzo


Ray

October 15, 2014 at 10:42 pm

The link you gave actually didn’t help much because I was already able to pull the metas like Event name date and total attendees but now I still can not get the fields like Venues and approved and unapproved attendees number of an specific event post. So please help me with it. Thank you in advance.


Josh

  • Support Staff

October 20, 2014 at 2:03 pm

Hi Ray,

We’ve integrated the Kint debugging tool into Event Espresso, so anywhere you want to get a better look at an object (or array, or string, or whatever), you can simply add something like:

global $post;
d( $post );

into your code, and it will output all kinds of wondrous information.
So if you were to add the above anywhere inside the “loop”, and take a look at one of the EE Event post objects, you will see that we have attached all of the event data to the WP post object, but we have ALSO attached our EE_Event Custom Post Type (CPT) object to it as well.
to get a better look at the EE CPT object, you could change the above to this:

global $post;
d( $post->EE_Event );

Notice that in the Kint output (click the + sign to expand the container) there is a tab named “Available Methods” (http://awesomescreenshot.com/00931ch406) ?
click on that to see a list of every function you can call directly on the EE_Event CPT object (it’s a big list).

Example 1: Venues

One of those methods is venues() (http://awesomescreenshot.com/04c31chd29)
so calling:

global $post;
$venues = $post->EE_Event->venues();

will give you an array of any related venues that belong to the event.
Now run d( $venues ); to see everything you can do with Venues (you’ll have to dig into that array of course).
Keep in mind that it’s always a wise idea to test the object you have before attempting to run methods on it, so do something like this first:

global $post;
if ( $post->EE_Event instanceof EE_Event ) {
  $venues = $post->EE_Event->venues();
  d( $venues );
}

Example 2: Number of Tickets Sold

Another one of the methods is get_number_of_tickets_sold() so calling:

EE_Event instanceof EE_Event ) {
  $tickets_sold = $post->EE_Event->get_number_of_tickets_sold();
  echo '

Number of tickets sold is: ' . $tickets_sold . '

'; } ?>

will echo the number of tickets sold for the event.

The support post ‘Getting all the event metas like Location,approved registration etc.’ 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