Last active
August 23, 2018 05:06
-
-
Save cliffordp/62360de9f1cb2b7b55b9bed080c173a6 to your computer and use it in GitHub Desktop.
The Events Calendar: Get all the Upcoming Events assigned a specific Event Category.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment