Query Events Use Case Examples

Basic Examples

Top ↑

Search for how many events are in the database

This also demonstrates the ->per_page() and ->count() functionality.

$result = tribe_events()->per_page( -1 )->count();

Top ↑

Get all events as objects

->all() will return a fully decorated post object, which can be used to print any post detail, for example, the event start date and the event title.

$results = tribe_events()
	->per_page( -1 )
	->all();

Top ↑

Return Titles of All Past Events

Filter events that start before a specified date with 'starts_before' and a PHP date time formatted string, then return all of those events using ->per_page( -1 ), and finally only output just the titles with ->pluck( 'post_title' );

$results = tribe_events()
	->where( 'starts_before', 'now' )
	->per_page( -1 )
	->pluck( 'post_title' );

Top ↑

Return Start Dates of All Events in a Specific Series

Filter events that are part of a specific event series with in_series and the post ID of the series, then return all of those events using ->per_page( -1 ), and finally only output just the start dates with ->pluck( 'start_date' );

$results = tribe_events()
	->where( 'in_series', 36 )
	->per_page( -1 )
	->pluck( 'start_date' );

Top ↑

Return All Past Events that are Part of Any Series

Filter events that are part of the event series with in_series and the boolean true, and then further filter them with ends_before with the value today, then return all of those events using ->per_page( -1 ), and finally only output just the event titles with ->pluck( 'post_title' );

$results = tribe_events()
	->where( 'in_series', true )
	->where( 'ends_before', 'today' )
	->per_page( -1 )
	->pluck( 'post_title' );