Documentation
Event Model
In this post, we’ll walk you through:
To retrieve information about an event, you can use the model class Cevento\Packages\Core\Models\Event.
This class provides various static helper methods for database queries.
Event Query
A single event can be retrieved with the following method:
use \Cevento\Packages\Core\Models\Event;
$event = Event::get($event_id);
To query multiple events, you can use the following method:
use \Cevento\Packages\Core\Models\Event;
$events = Event::getAll($query_args = []);
Additional filter and sort parameters can be passed via the $query_args array.
It expects the standard structure of the parameter for the method WP_Query::parse_query($query_args).
A full overview of all possible parameters can be found in the official WordPress documentation.
Event Data Structure
Events are returned as associative arrays with the following structure:
| Key | Type | Description |
|---|---|---|
| id | Integer | The ID of the event |
| title | String | The name of the event |
| description | String | The unformatted description of the event |
| html_description | String | The formatted description of the event |
| fullday | Boolean | Whether the event is all-day |
| createdAt | DateTime | Event creation date |
| startsAt | DateTime | Event start date and time |
| endsAt | DateTime | Event end date and time |
| bookingEnabled | Boolean | Whether bookings for this event are enabled in the backend. Note: This only refers to the checkbox setting in the event and does not consider available spots or the defined booking period. |
| bookingForm | Integer, Null | The ID of the linked booking form |
| bookingMaxPlaces | Integer | The maximum number of available spots |
| bookingStartsAt | DateTime | Date and time when bookings open |
| bookingEndsAt | DateTime | Date and time when bookings close |
| address | String | The event address |
| addressName | String | The label/name of the event location |
| coordinates | String | The coordinates of the event location (lat,lng) |
| bookingConfirmationRequired | Boolean | Whether a booking must be confirmed by an administrator |
| categories | Array | All categories linked to the event |
| url | String | The link to the single event view |
| status | String | The current publication status of the event |
| dateTime | String | Formatted time interval of the event |
Stored Dates (since 3.4.0)
All dates are stored as unix timestamps, so changing the site’s timezone doesn’t move them. Use the values of Event::get() (startsAt, endsAt, … as DateTime objects in the site’s timezone) instead of reading the meta fields directly.
| Meta key | Content |
|---|---|
datetime_from, datetime_until |
Timed events: the timestamp of the moment. Full-day events: the timestamp of the calendar date at 00:00 UTC, so a full-day event stays on its date when the timezone changes. Empty datetime_until: open-ended. |
booking_available_from, booking_available_until |
Timestamp of the moment |
_cevento_starts_at, _cevento_ends_at |
The real start and end moment of every event (derived, maintained automatically). Use them to filter or sort events by date. |
To write dates, you can pass timestamps or site-local strings (Y-m-d H:i:s) to Event::create() — they are converted. To query events by date, use Event::dateQuery():
use \Cevento\Packages\Core\Models\Event;
use \Cevento\Packages\Helpers\Date;
// Events starting within the next 30 days, soonest first
$events = Event::getAll([
'meta_query' => [
Event::dateQuery('datetime_from', '>=', Date::now()),
Event::dateQuery('datetime_from', '<', Date::now()->modify('+30 days')),
],
]);
Additional Methods
Metadata Queries
use \Cevento\Packages\Core\Models\Event;
// Checks if an event is in the future
Event::isUpcoming($event_id): bool
// Returns the formatted time period of an event
Event::getDateTime($event_id): string
// Returns the value of an event editor field – also one of your own, added
// through cevento/event_metadata. $event: event ID, event array or null for
// the current post. Without a saved value: $default, else the field's
// "default", else null.
Event::getMeta($event, string $key, mixed $default = null): mixed
Booking Queries
use \Cevento\Packages\Core\Models\Event;
// Checks if bookings are active for an event
Event::isBookingActive($event_id): bool
// Checks if there are still available spots for the event
Event::hasPlacesAvailable($event_id): bool
// Checks if an event is fully booked
Event::isFull($event_id): bool
// Returns the number of available spots
Event::getAvailablePlaces($event_id): int
// Returns the availability status as a formatted string
Event::getAvailablePlacesText($event_id): string