Skip to content

Instantly share code, notes, and snippets.

@cliffordp
Last active February 20, 2024 13:36
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cliffordp/1b8c808efa4256ebcef2d8805f069595 to your computer and use it in GitHub Desktop.
Save cliffordp/1b8c808efa4256ebcef2d8805f069595 to your computer and use it in GitHub Desktop.
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