Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
The Events Calendar - Get the next upcoming Featured Event
<?php
/**
* The Events Calendar - Get the next upcoming Featured Event
*
* Notes:
* 1) Ignores all-day events.
* 2) For the date comparison, this code assumes each event is in
* the same timezone as your WordPress General Settings timezone.
*
* @link https://gist.github.com/cliffordp/1b8c808efa4256ebcef2d8805f069595
* @link https://theeventscalendar.com/support/forums/topic/pull-in-latest-featured-event/
* @link https://make.wordpress.org/core/2014/08/29/a-more-powerful-order-by-in-wordpress-4-0/
* @link https://theeventscalendar.com/knowledgebase/using-tribe_get_events/
*/
$args = array(
'eventDisplay' => 'custom',
'posts_per_page' => 1,
'meta_query' => array(
'relation' => 'AND',
'featured' => array(
'key' => Tribe__Events__Featured_Events::FEATURED_EVENT_KEY,
'compare' => 'EXISTS',
),
'start_date' => array(
'key' => '_EventStartDate',
'value' => current_time( 'mysql' ),
'compare' => '>=',
'type' => 'DATETIME',
),
),
'orderby' => array(
'start_date' => 'ASC',
),
);
$events = tribe_get_events( $args );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment