The Events Calendar: Get all the Upcoming Events assigned a specific Event Category.
<?php
/**
* The Events Calendar: Get all the Upcoming Events assigned a specific Event Category.
*
* A utility function to be used as part of a bigger customization.
*
* @link https://gist.github.com/cliffordp/62360de9f1cb2b7b55b9bed080c173a6 This snippet.
* @link https://theeventscalendar.com/knowledgebase/using-tribe_get_events/
*
* @see tribe_get_events()
*
* @param int $event_category_term_id The Term ID of an Event Category.
*
* @return array
*/
function cliff_tec_get_all_upcoming_events_from_event_category( $event_category_term_id = 0 ) {
$event_category_term_id = (int) $event_category_term_id;
$upcoming_events_in_event_category = array();
if (
class_exists( 'Tribe__Events__Main' )
&& 0 < $event_category_term_id
) {
$upcoming_events_in_event_category = tribe_get_events(
array(
'posts_per_page' => -1, // unlimited
'tax_query' => array(
array(
'taxonomy' => Tribe__Events__Main::instance()->get_event_taxonomy(),
'terms' => $event_category_term_id
)
),
)
);
}
return $upcoming_events_in_event_category;
}