Support

Home Forums Event Espresso Premium Template Tags for event meta

Template Tags for event meta

Posted: February 11, 2021 at 6:53 am

Viewing 6 reply threads


Mark

February 11, 2021 at 6:53 am

Is there any template tag to get event price, event time, and available space to register in the event?
I don’t see any of them here
https://eventespresso.com/wiki/ee4-themes-templates/


Mark

February 12, 2021 at 12:41 am

I have managed to get the event time and date but still suffering to get the event price and available space for attendees to be registerd?


Tony

  • Support Staff

February 15, 2021 at 4:13 am

Hi Mark,

By available space for attendees do you mean spaces still for sale or in total?

If you have an EE_Event object you get both with something like:

// Spaces remaining for sale.
echo $event->spaces_remaining_for_sale();
// Total available spaces.
echo $event->total_available_spaces();

The price of an event is a little more tricky as you assign prices to tickets within an event, if you have multiple tickets which price are you showing?

// grab array of EE_Ticket objects for event
$tickets = EEH_Event_View::event_tickets_available( $post->ID );
			
// grab first ticket from array
$ticket = reset( $tickets );

//check if the ticket is free, if set the ticket price to 'Free'
if ( $ticket instanceof EE_Ticket ) {
    $ticket_price = $ticket->pretty_price();
    $ticket_price_data_value = $ticket->price();
    $ticket_price = $ticket_price_data_value == 0 ? __( 'Free', 'event_espresso' ) : $ticket_price;
}

echo $ticket_price;


Mark

February 16, 2021 at 3:49 am

I don’t have an EE_Event object on my page. Would you please tell me which class I have to include in the page file to create an EE_Event object?
Thanks.


Tony

  • Support Staff

February 16, 2021 at 4:23 am

Do you have a WP_Post object for the espresso_event post?

Aka a $post variable from the main query for an EE event post.

If so it should have the EE_Event object set as an additional property, so if you don’t have an EE_Event object but do have the WP_Post object for it, you can use:

if ($post instanceof WP_Post
    && $post->post_type === 'espresso_events'
    && isset($post->EE_Event)
){
    $event = $post->EE_Event;
}

$event should now be an instance of EE_Event for the current post.

However, we also have a helper method that can pull this in for you:

$event = EEH_Event_View::get_event($post->ID);


Mark

February 16, 2021 at 4:32 am

For this reply, I Must say Tony you are Awesome.
Thanks.


Tony

  • Support Staff

February 16, 2021 at 5:43 am

Thanks and you’re most welcome.

Something I do recommend when working with EE models/object (like the EE_Event object), is Kint:

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

Wrap your variable within d(); and you’ll get an awesome output that lists all of the methods available on the object.

It really helps find the method/property you want/need when working with the models:

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

Viewing 6 reply threads

The support post ‘Template Tags for event meta’ 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