Getting Elements

Ticket Queries

You can fetch tickets in your templates or PHP code using ticket queries.

{# Create a new ticket query #}
{% set myQuery = craft.events.tickets() %}
// Create a new ticket query
$myQuery = \verbb\events\elements\Ticket::find();

Once you’ve created a ticket query, you can set parameters on it to narrow down the results, and then execute it by calling .all(). An array of Ticket objects will be returned.

See Element Queries (opens new window) in the Craft docs to learn how element queries work.

Example

A ticket is the purchasable for one ticket type in one session, so you can list what a customer can buy for an event by doing the following.

  1. Create a ticket query with craft.events.tickets().
  2. Set the event parameter on it.
  3. Fetch the tickets with .all().
  4. Loop through the tickets using a for (opens new window) tag to output their contents.

This example assumes an event variable, such as on an event’s template.

{# Create a ticket query with the 'event' parameter #}
{% set tickets = craft.events.tickets()
    .event(event)
    .all() %}

{# Display their contents #}
{% for ticket in tickets %}
    <p>{{ ticket.title }}, {{ ticket.price|commerceCurrency(cart.currency) }}</p>
{% endfor %}

The cart variable is Craft Commerce’s current cart, available as craft.commerce.carts.cart.

Parameters

Ticket queries support the following parameters.

asArray

Causes the query to return matching tickets as arrays of data, rather than Ticket objects.

{# Fetch tickets as arrays #}
{% set tickets = craft.events.tickets()
    .asArray()
    .all() %}
// Fetch tickets as arrays
$tickets = \verbb\events\elements\Ticket::find()
    ->asArray()
    ->all();

dateCreated

Narrows the query results based on the tickets’ creation dates.

ValueFetches tickets…
'>= 2026-04-01'that were created on or after 2026-04-01.
'< 2026-05-01'that were created before 2026-05-01.
['and', '>= 2026-04-01', '< 2026-05-01']that were created between 2026-04-01 and 2026-05-01.
{# Fetch tickets created last month #}
{% set start = date('first day of last month')|atom %}
{% set end = date('first day of this month')|atom %}

{% set tickets = craft.events.tickets()
    .dateCreated(['and', ">= #{start}", "< #{end}"])
    .all() %}
// Fetch tickets created last month
$start = (new \DateTime('first day of last month'))->format(\DateTime::ATOM);
$end = (new \DateTime('first day of this month'))->format(\DateTime::ATOM);

$tickets = \verbb\events\elements\Ticket::find()
    ->dateCreated(['and', ">= {$start}", "< {$end}"])
    ->all();

dateUpdated

Narrows the query results based on the tickets’ last-updated dates.

ValueFetches tickets…
'>= 2026-04-01'that were updated on or after 2026-04-01.
'< 2026-05-01'that were updated before 2026-05-01.
['and', '>= 2026-04-01', '< 2026-05-01']that were updated between 2026-04-01 and 2026-05-01.
{# Fetch tickets updated in the last week #}
{% set lastWeek = date('1 week ago')|atom %}

{% set tickets = craft.events.tickets()
    .dateUpdated(">= #{lastWeek}")
    .all() %}
// Fetch tickets updated in the last week
$lastWeek = (new \DateTime('1 week ago'))->format(\DateTime::ATOM);

$tickets = \verbb\events\elements\Ticket::find()
    ->dateUpdated(">= {$lastWeek}")
    ->all();

event

Narrows the query results to tickets for an event.

ValueFetches tickets…
an Event objectfor the event.
1for an event with an ID of 1.
{# Fetch tickets for an event #}
{% set tickets = craft.events.tickets()
    .event(event)
    .all() %}
// Fetch tickets for an event
$tickets = \verbb\events\elements\Ticket::find()
    ->event($event)
    ->all();

eventId

Narrows the query results based on the tickets’ events, per the events’ IDs.

ValueFetches tickets…
1for an event with an ID of 1.
'not 1'not for an event with an ID of 1.
[1, 2]for an event with an ID of 1 or 2.
['not', 1, 2]not for an event with an ID of 1 or 2.
{# Fetch tickets for the event with an ID of 1 #}
{% set tickets = craft.events.tickets()
    .eventId(1)
    .all() %}
// Fetch tickets for the event with an ID of 1
$tickets = \verbb\events\elements\Ticket::find()
    ->eventId(1)
    ->all();

fixedOrder

Causes the query results to be returned in the order specified by id.

{# Fetch tickets in a specific order #}
{% set tickets = craft.events.tickets()
    .id([1, 2, 3, 4, 5])
    .fixedOrder()
    .all() %}
// Fetch tickets in a specific order
$tickets = \verbb\events\elements\Ticket::find()
    ->id([1, 2, 3, 4, 5])
    ->fixedOrder()
    ->all();

hasEvent

Narrows the query results to tickets whose event matches an event query, or an array of event query criteria.

ValueFetches tickets…
an EventQuery objectwhose event matches the query.
an array of criteriawhose event matches the criteria.
{# Fetch tickets for live conference events #}
{% set tickets = craft.events.tickets()
    .hasEvent({ type: 'conference', status: 'live' })
    .all() %}
// Fetch tickets for live conference events
$tickets = \verbb\events\elements\Ticket::find()
    ->hasEvent(['type' => 'conference', 'status' => 'live'])
    ->all();

id

Narrows the query results based on the tickets’ IDs.

ValueFetches tickets…
1with an ID of 1.
'not 1'not with an ID of 1.
[1, 2]with an ID of 1 or 2.
['not', 1, 2]not with an ID of 1 or 2.
{# Fetch the ticket by its ID #}
{% set ticket = craft.events.tickets()
    .id(1)
    .one() %}
// Fetch the ticket by its ID
$ticket = \verbb\events\elements\Ticket::find()
    ->id(1)
    ->one();

This can be combined with fixedOrder if you want the results to be returned in a specific order.

inReverse

Causes the query results to be returned in reverse order.

{# Fetch tickets in reverse #}
{% set tickets = craft.events.tickets()
    .inReverse()
    .all() %}
// Fetch tickets in reverse
$tickets = \verbb\events\elements\Ticket::find()
    ->inReverse()
    ->all();

limit

Determines the number of tickets that should be returned.

{# Fetch up to 10 tickets #}
{% set tickets = craft.events.tickets()
    .limit(10)
    .all() %}
// Fetch up to 10 tickets
$tickets = \verbb\events\elements\Ticket::find()
    ->limit(10)
    ->all();

offset

Determines how many tickets should be skipped in the results.

{# Fetch all tickets except for the first 3 #}
{% set tickets = craft.events.tickets()
    .offset(3)
    .all() %}
// Fetch all tickets except for the first 3
$tickets = \verbb\events\elements\Ticket::find()
    ->offset(3)
    ->all();

orderBy

Determines the order that the tickets should be returned in. Tickets are ordered by their session, then their ticket type, following the order on their event by default.

{# Fetch all tickets in order of date created #}
{% set tickets = craft.events.tickets()
    .orderBy('elements.dateCreated asc')
    .all() %}
// Fetch all tickets in order of date created
$tickets = \verbb\events\elements\Ticket::find()
    ->orderBy('elements.dateCreated asc')
    ->all();

price

Narrows the query results based on the tickets’ prices. Tickets are Craft Commerce purchasables, so Commerce’s other purchasable parameters, such as availableForPurchase, also work on ticket queries.

ValueFetches tickets…
20with a price of 20.
'< 20'with a price less than 20.
['and', '>= 10', '<= 50']with a price between 10 and 50.
{# Fetch tickets that cost less than 20 #}
{% set tickets = craft.events.tickets()
    .price('< 20')
    .all() %}
// Fetch tickets that cost less than 20
$tickets = \verbb\events\elements\Ticket::find()
    ->price('< 20')
    ->all();

relatedTo

Narrows the query results to only tickets that are related to certain other elements. See Relations (opens new window) in the Craft docs for a full explanation of how to work with this parameter.

{# Fetch all tickets that are related to myCategory #}
{% set tickets = craft.events.tickets()
    .relatedTo(myCategory)
    .all() %}
// Fetch all tickets that are related to myCategory
$tickets = \verbb\events\elements\Ticket::find()
    ->relatedTo($myCategory)
    ->all();

Narrows the query results to only tickets that match a search query. See Searching (opens new window) in the Craft docs for a full explanation of how to work with this parameter.

{# Fetch all tickets that match the search query #}
{% set searchQuery = craft.app.request.getQueryParam('q') %}

{% set tickets = craft.events.tickets()
    .search(searchQuery)
    .all() %}
// Fetch all tickets that match the search query
$searchQuery = \Craft::$app->getRequest()->getQueryParam('q');

$tickets = \verbb\events\elements\Ticket::find()
    ->search($searchQuery)
    ->all();

session

Narrows the query results to tickets for a session.

ValueFetches tickets…
a Session objectfor the session.
1for a session with an ID of 1.
{# Fetch tickets for a session #}
{% set tickets = craft.events.tickets()
    .session(session)
    .all() %}
// Fetch tickets for a session
$tickets = \verbb\events\elements\Ticket::find()
    ->session($session)
    ->all();

sessionId

Narrows the query results based on the tickets’ sessions, per the sessions’ IDs.

ValueFetches tickets…
1for a session with an ID of 1.
'not 1'not for a session with an ID of 1.
[1, 2]for a session with an ID of 1 or 2.
['not', 1, 2]not for a session with an ID of 1 or 2.
{# Fetch tickets for the session with an ID of 1 #}
{% set tickets = craft.events.tickets()
    .sessionId(1)
    .all() %}
// Fetch tickets for the session with an ID of 1
$tickets = \verbb\events\elements\Ticket::find()
    ->sessionId(1)
    ->all();

sku

Narrows the query results based on the tickets’ SKUs.

ValueFetches tickets…
'foo'with a SKU of foo.
'foo*'with a SKU that begins with foo.
'*foo'with a SKU that ends with foo.
'*foo*'with a SKU that contains foo.
'not *foo*'with a SKU that doesn’t contain foo.
['*foo*', '*bar*']with a SKU that contains foo or bar.
['not', '*foo*', '*bar*']with a SKU that doesn’t contain foo or bar.
{# Fetch the ticket with a SKU of CONF-ADULT #}
{% set ticket = craft.events.tickets()
    .sku('CONF-ADULT')
    .one() %}
// Fetch the ticket with a SKU of CONF-ADULT
$ticket = \verbb\events\elements\Ticket::find()
    ->sku('CONF-ADULT')
    ->one();

status

Narrows the query results based on the tickets’ statuses. Pass null to fetch tickets regardless of their status.

ValueFetches tickets…
'enabled' (default)that are enabled.
'disabled'that are disabled.
['enabled', 'disabled']that are enabled or disabled.
nullregardless of status.
{# Fetch disabled tickets #}
{% set tickets = craft.events.tickets()
    .status('disabled')
    .all() %}
// Fetch disabled tickets
$tickets = \verbb\events\elements\Ticket::find()
    ->status('disabled')
    ->all();

type

Narrows the query results to tickets of a ticket type.

ValueFetches tickets…
a TicketType objectof the ticket type.
1of a ticket type with an ID of 1.
{# Fetch tickets of a ticket type #}
{% set tickets = craft.events.tickets()
    .type(ticketType)
    .all() %}
// Fetch tickets of a ticket type
$tickets = \verbb\events\elements\Ticket::find()
    ->type($ticketType)
    ->all();

typeId

Narrows the query results based on the tickets’ ticket types, per the ticket types’ IDs.

ValueFetches tickets…
1of a ticket type with an ID of 1.
'not 1'not of a ticket type with an ID of 1.
[1, 2]of a ticket type with an ID of 1 or 2.
['not', 1, 2]not of a ticket type with an ID of 1 or 2.
{# Fetch tickets of the ticket type with an ID of 1 #}
{% set tickets = craft.events.tickets()
    .typeId(1)
    .all() %}
// Fetch tickets of the ticket type with an ID of 1
$tickets = \verbb\events\elements\Ticket::find()
    ->typeId(1)
    ->all();

uid

Narrows the query results based on the tickets’ UIDs.

{# Fetch the ticket by its UID #}
{% set ticket = craft.events.tickets()
    .uid('xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx')
    .one() %}
// Fetch the ticket by its UID
$ticket = \verbb\events\elements\Ticket::find()
    ->uid('xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx')
    ->one();

with

Causes the query to return matching tickets eager-loaded with related elements. See Eager-Loading Elements (opens new window) in the Craft docs for a full explanation of how to work with this parameter.

{# Fetch tickets eager-loaded with the “Related” field’s relations #}
{% set tickets = craft.events.tickets()
    .with(['related'])
    .all() %}
// Fetch tickets eager-loaded with the “Related” field’s relations
$tickets = \verbb\events\elements\Ticket::find()
    ->with(['related'])
    ->all();