Session Queries
You can fetch sessions in your templates or PHP code using session queries.
{# Create a new session query #}
{% set myQuery = craft.events.sessions() %}// Create a new session query
$myQuery = \verbb\events\elements\Session::find();Once you’ve created a session query, you can set parameters on it to narrow down the results, and then execute it by calling .all(). An array of Session objects will be returned.
See Element Queries (opens new window) in the Craft docs to learn how element queries work.
Example
You can list the upcoming sessions for an event by doing the following.
- Create a session query with
craft.events.sessions(). - Set the event and startDate parameters on it.
- Fetch the sessions with
.all(). - Loop through the sessions using a for (opens new window) tag to output their contents.
This example assumes an event variable, such as on an event’s template.
{% set today = date('today')|atom %}
{# Create a session query with the 'event' and 'startDate' parameters #}
{% set sessions = craft.events.sessions()
.event(event)
.startDate(">= #{today}")
.all() %}
{# Display their contents #}
{% for session in sessions %}
<p>{{ session.title }}, {{ session.startDate|date('short') }}</p>
{% endfor %}Parameters
Session queries support the following parameters.
Narrows the query results based on whether the sessions’ events can be drafts. Pass false to exclude sessions that belong to event drafts.
{# Fetch sessions that don’t belong to event drafts #}
{% set sessions = craft.events.sessions()
.allowOwnerDrafts(false)
.all() %}// Fetch sessions that don’t belong to event drafts
$sessions = \verbb\events\elements\Session::find()
->allowOwnerDrafts(false)
->all();Narrows the query results based on whether the sessions’ events can be revisions. Pass false to exclude sessions that belong to event revisions.
{# Fetch sessions that don’t belong to event revisions #}
{% set sessions = craft.events.sessions()
.allowOwnerRevisions(false)
.all() %}// Fetch sessions that don’t belong to event revisions
$sessions = \verbb\events\elements\Session::find()
->allowOwnerRevisions(false)
->all();Causes the query to return matching sessions as arrays of data, rather than Session objects.
{# Fetch sessions as arrays #}
{% set sessions = craft.events.sessions()
.asArray()
.all() %}// Fetch sessions as arrays
$sessions = \verbb\events\elements\Session::find()
->asArray()
->all();Narrows the query results based on the sessions’ shared capacity.
| Value | Fetches sessions… |
|---|---|
100 | with a capacity of 100. |
'>= 100' | with a capacity of 100 or more. |
':empty:' | with no capacity set. |
{# Fetch sessions with a capacity of 100 or more #}
{% set sessions = craft.events.sessions()
.capacity('>= 100')
.all() %}// Fetch sessions with a capacity of 100 or more
$sessions = \verbb\events\elements\Session::find()
->capacity('>= 100')
->all();Narrows the query results based on the sessions’ creation dates.
| Value | Fetches sessions… |
|---|---|
'>= 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 sessions created last month #}
{% set start = date('first day of last month')|atom %}
{% set end = date('first day of this month')|atom %}
{% set sessions = craft.events.sessions()
.dateCreated(['and', ">= #{start}", "< #{end}"])
.all() %}// Fetch sessions 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);
$sessions = \verbb\events\elements\Session::find()
->dateCreated(['and', ">= {$start}", "< {$end}"])
->all();Narrows the query results based on the sessions’ last-updated dates.
| Value | Fetches sessions… |
|---|---|
'>= 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 sessions updated in the last week #}
{% set lastWeek = date('1 week ago')|atom %}
{% set sessions = craft.events.sessions()
.dateUpdated(">= #{lastWeek}")
.all() %}// Fetch sessions updated in the last week
$lastWeek = (new \DateTime('1 week ago'))->format(\DateTime::ATOM);
$sessions = \verbb\events\elements\Session::find()
->dateUpdated(">= {$lastWeek}")
->all();Narrows the query results based on the sessions’ end dates.
| Value | Fetches sessions… |
|---|---|
'>= 2026-04-01' | that finish on or after 2026-04-01. |
'< 2026-05-01' | that finish before 2026-05-01. |
['and', '>= 2026-04-01', '< 2026-05-01'] | that finish between 2026-04-01 and 2026-05-01. |
{# Fetch sessions that finish today or later #}
{% set today = date('today')|atom %}
{% set sessions = craft.events.sessions()
.endDate(">= #{today}")
.all() %}// Fetch sessions that finish today or later
$today = (new \DateTime('today'))->format(\DateTime::ATOM);
$sessions = \verbb\events\elements\Session::find()
->endDate(">= {$today}")
->all();Narrows the query results to sessions that belong to an event.
| Value | Fetches sessions… |
|---|---|
an Event object | that belong to the event. |
1 | that belong to an event with an ID of 1. |
{# Fetch sessions for an event #}
{% set sessions = craft.events.sessions()
.event(event)
.all() %}// Fetch sessions for an event
$sessions = \verbb\events\elements\Session::find()
->event($event)
->all();Narrows the query results based on the sessions’ events, per the events’ IDs.
| Value | Fetches sessions… |
|---|---|
1 | that belong to an event with an ID of 1. |
'not 1' | not that belong to an event with an ID of 1. |
[1, 2] | that belong to an event with an ID of 1 or 2. |
['not', 1, 2] | not that belong to an event with an ID of 1 or 2. |
{# Fetch sessions for the event with an ID of 1 #}
{% set sessions = craft.events.sessions()
.eventId(1)
.all() %}// Fetch sessions for the event with an ID of 1
$sessions = \verbb\events\elements\Session::find()
->eventId(1)
->all();Causes the query results to be returned in the order specified by id.
{# Fetch sessions in a specific order #}
{% set sessions = craft.events.sessions()
.id([1, 2, 3, 4, 5])
.fixedOrder()
.all() %}// Fetch sessions in a specific order
$sessions = \verbb\events\elements\Session::find()
->id([1, 2, 3, 4, 5])
->fixedOrder()
->all();Narrows the query results to sessions in a recurring group, per the group’s UID. Sessions generated from the same frequency share a group UID.
{# Fetch the other sessions in the same recurring group #}
{% set sessions = craft.events.sessions()
.groupUid(session.groupUid)
.all() %}// Fetch the other sessions in the same recurring group
$sessions = \verbb\events\elements\Session::find()
->groupUid($session->groupUid)
->all();Narrows the query results to sessions whose event matches an event query, or an array of event query criteria.
| Value | Fetches sessions… |
|---|---|
an EventQuery object | whose event matches the query. |
| an array of criteria | whose event matches the criteria. |
{# Fetch sessions for live conference events #}
{% set sessions = craft.events.sessions()
.hasEvent({ type: 'conference', status: 'live' })
.all() %}// Fetch sessions for live conference events
$sessions = \verbb\events\elements\Session::find()
->hasEvent(['type' => 'conference', 'status' => 'live'])
->all();Narrows the query results based on the sessions’ IDs.
| Value | Fetches sessions… |
|---|---|
1 | with 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 session by its ID #}
{% set session = craft.events.sessions()
.id(1)
.one() %}// Fetch the session by its ID
$session = \verbb\events\elements\Session::find()
->id(1)
->one();This can be combined with fixedOrder if you want the results to be returned in a specific order.
Causes the query results to be returned in reverse order.
{# Fetch sessions in reverse #}
{% set sessions = craft.events.sessions()
.inReverse()
.all() %}// Fetch sessions in reverse
$sessions = \verbb\events\elements\Session::find()
->inReverse()
->all();Narrows the query results based on whether the sessions were generated from a recurring frequency.
{# Fetch recurring sessions #}
{% set sessions = craft.events.sessions()
.isRecurring(true)
.all() %}// Fetch recurring sessions
$sessions = \verbb\events\elements\Session::find()
->isRecurring(true)
->all();Determines the number of sessions that should be returned.
{# Fetch up to 10 sessions #}
{% set sessions = craft.events.sessions()
.limit(10)
.all() %}// Fetch up to 10 sessions
$sessions = \verbb\events\elements\Session::find()
->limit(10)
->all();Determines how many sessions should be skipped in the results.
{# Fetch all sessions except for the first 3 #}
{% set sessions = craft.events.sessions()
.offset(3)
.all() %}// Fetch all sessions except for the first 3
$sessions = \verbb\events\elements\Session::find()
->offset(3)
->all();Determines the order that the sessions should be returned in. Sessions are ordered by the order they appear in on their event by default.
{# Fetch all sessions in order of date created #}
{% set sessions = craft.events.sessions()
.orderBy('elements.dateCreated asc')
.all() %}// Fetch all sessions in order of date created
$sessions = \verbb\events\elements\Session::find()
->orderBy('elements.dateCreated asc')
->all();Narrows the query results to sessions owned by an event, and sets the site to the event’s site. Use event when you only need to match the event ID.
{# Fetch sessions owned by an event #}
{% set sessions = craft.events.sessions()
.owner(event)
.all() %}// Fetch sessions owned by an event
$sessions = \verbb\events\elements\Session::find()
->owner($event)
->all();Narrows the query results based on the IDs of the events that own the sessions.
| Value | Fetches sessions… |
|---|---|
1 | owned by an event with an ID of 1. |
'not 1' | not owned by an event with an ID of 1. |
[1, 2] | owned by an event with an ID of 1 or 2. |
['not', 1, 2] | not owned by an event with an ID of 1 or 2. |
{# Fetch sessions owned by the event with an ID of 1 #}
{% set sessions = craft.events.sessions()
.ownerId(1)
.all() %}// Fetch sessions owned by the event with an ID of 1
$sessions = \verbb\events\elements\Session::find()
->ownerId(1)
->all();Narrows the query results to sessions whose primary owner is an event, and sets the site to the event’s site. A session is only ever created on one event, which is its primary owner, though drafts and revisions of that event also own it.
{# Fetch sessions created on an event #}
{% set sessions = craft.events.sessions()
.primaryOwner(event)
.all() %}// Fetch sessions created on an event
$sessions = \verbb\events\elements\Session::find()
->primaryOwner($event)
->all();Narrows the query results based on the IDs of the sessions’ primary owners.
| Value | Fetches sessions… |
|---|---|
1 | whose primary owner has an ID of 1. |
'not 1' | not whose primary owner has an ID of 1. |
[1, 2] | whose primary owner has an ID of 1 or 2. |
['not', 1, 2] | not whose primary owner has an ID of 1 or 2. |
{# Fetch sessions created on the event with an ID of 1 #}
{% set sessions = craft.events.sessions()
.primaryOwnerId(1)
.all() %}// Fetch sessions created on the event with an ID of 1
$sessions = \verbb\events\elements\Session::find()
->primaryOwnerId(1)
->all();Narrows the query results to only sessions 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 sessions that are related to myCategory #}
{% set sessions = craft.events.sessions()
.relatedTo(myCategory)
.all() %}// Fetch all sessions that are related to myCategory
$sessions = \verbb\events\elements\Session::find()
->relatedTo($myCategory)
->all();Narrows the query results to only sessions 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 sessions that match the search query #}
{% set searchQuery = craft.app.request.getQueryParam('q') %}
{% set sessions = craft.events.sessions()
.search(searchQuery)
.all() %}// Fetch all sessions that match the search query
$searchQuery = \Craft::$app->getRequest()->getQueryParam('q');
$sessions = \verbb\events\elements\Session::find()
->search($searchQuery)
->all();Determines which site the sessions should be queried in. The current site is used by default.
| Value | Fetches sessions… |
|---|---|
'foo' | from the site with a handle of foo. |
['foo', 'bar'] | from a site with a handle of foo or bar. |
'*' | from any site. |
a craft\models\Site object | from the site represented by the object. |
{# Fetch sessions from the Foo site #}
{% set sessions = craft.events.sessions()
.site('foo')
.all() %}// Fetch sessions from the Foo site
$sessions = \verbb\events\elements\Session::find()
->site('foo')
->all();Determines which site the sessions should be queried in, per the site’s ID. The current site is used by default.
{# Fetch sessions from the site with an ID of 1 #}
{% set sessions = craft.events.sessions()
.siteId(1)
.all() %}// Fetch sessions from the site with an ID of 1
$sessions = \verbb\events\elements\Session::find()
->siteId(1)
->all();Narrows the query results based on the sessions’ start dates.
| Value | Fetches sessions… |
|---|---|
'>= 2026-04-01' | that start on or after 2026-04-01. |
'< 2026-05-01' | that start before 2026-05-01. |
['and', '>= 2026-04-01', '< 2026-05-01'] | that start between 2026-04-01 and 2026-05-01. |
{# Fetch sessions that start today or later #}
{% set today = date('today')|atom %}
{% set sessions = craft.events.sessions()
.startDate(">= #{today}")
.all() %}// Fetch sessions that start today or later
$today = (new \DateTime('today'))->format(\DateTime::ATOM);
$sessions = \verbb\events\elements\Session::find()
->startDate(">= {$today}")
->all();Narrows the query results based on the sessions’ statuses. Pass null to fetch sessions regardless of their status.
| Value | Fetches sessions… |
|---|---|
'enabled' (default) | that are enabled. |
'disabled' | that are disabled. |
['enabled', 'disabled'] | that are enabled or disabled. |
null | regardless of status. |
{# Fetch disabled sessions #}
{% set sessions = craft.events.sessions()
.status('disabled')
.all() %}// Fetch disabled sessions
$sessions = \verbb\events\elements\Session::find()
->status('disabled')
->all();Narrows the query results based on the sessions’ titles.
| Value | Fetches sessions… |
|---|---|
'foo' | with a title of foo. |
'foo*' | with a title that begins with foo. |
'*foo' | with a title that ends with foo. |
'*foo*' | with a title that contains foo. |
'not *foo*' | with a title that doesn’t contain foo. |
['*foo*', '*bar*'] | with a title that contains foo or bar. |
['not', '*foo*', '*bar*'] | with a title that doesn’t contain foo or bar. |
{# Fetch sessions with a title that contains "Foo" #}
{% set sessions = craft.events.sessions()
.title('*Foo*')
.all() %}// Fetch sessions with a title that contains "Foo"
$sessions = \verbb\events\elements\Session::find()
->title('*Foo*')
->all();Narrows the query results based on the sessions’ UIDs.
{# Fetch the session by its UID #}
{% set session = craft.events.sessions()
.uid('xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx')
.one() %}// Fetch the session by its UID
$session = \verbb\events\elements\Session::find()
->uid('xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx')
->one();Causes the query to return matching sessions 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 sessions eager-loaded with the “Related” field’s relations #}
{% set sessions = craft.events.sessions()
.with(['related'])
.all() %}// Fetch sessions eager-loaded with the “Related” field’s relations
$sessions = \verbb\events\elements\Session::find()
->with(['related'])
->all();