Support

Home Forums Event Espresso Premium Get All Ticket Id's for an Event

Get All Ticket Id's for an Event

Posted: December 28, 2021 at 5:51 pm

Viewing 3 reply threads


academytrained

December 28, 2021 at 5:51 pm

I am looking for a way to get all of the ticket ID’s for an event within the Single event template. We use the LearnDash addon and looking to only show tickets for a user if they have the prerequisite course completed. We believe we can do this, but need a way to get all the ticket IDs so we can then subsequently grab the course Ids from the ticket.

Is there a method for retrieving the tickets for the current event or a specific event ID?


Tony

  • Support Staff

December 29, 2021 at 8:46 am

Hi there,

Yes, you can use our model system to grab those details fairly easily. If you are going to do any custom dev work for Event Espresso I highly recommend taking a look at the Model System docs here:

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

The models make getting the data you need much easier than rolling your own as they handle all of the joins etc for you.

If you already have an EE_Event object then you can do something like:

$tickets = $event->active_tickets();

Which returns an array of EE_Ticket objects that have not expired, loop over those for the IDs:

$tkt_ids = array();
foreach($tickets as $ticket) {
    if($ticket instanceof EE_Ticket) {
       $tkt_ids[] = $ticket->ID();
    }
}

The above isn’t the most efficient method as all you want is the ID’s and you’ll get EE_Ticket objects, but it’s easily readable.

If you don’t have the EE_Event object, you can use $event = EEH_Event_View::get_event(); from within the single event output and EE will do its best to pull that object in for you without the ID.


academytrained

January 7, 2022 at 11:03 am

Hey Tony, this was exactly what I needed. Thank you!


Tony

  • Support Staff

January 7, 2022 at 11:55 am

You’re most welcome 🙂

Viewing 3 reply threads

The support post ‘Get All Ticket Id's for an Event’ 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