Show upcoming events from The Events Calendar

You can use Display Posts Shortcode to list upcoming events from The Events Calendar.

Add the code below to your theme or core functionality plugin, then display events like this: 

<?php
/**
* Display Posts - List upcoming events from The Events Calendar
* @see https://displayposts.com/2019/01/04/display-upcoming-events-from-the-events-calendar/
*/
function be_dps_future_events( $args, $atts ) {
// Only run on event queries
if( 'tribe_events' != $args['post_type'] )
return $args;
$args['order'] = 'ASC';
$args['orderby'] = 'meta_value';
$args['meta_key'] = '_EventStartDate';
$args['meta_type'] = 'DATETIME';
$args['meta_query'] = array(
array(
'key' => '_EventStartDate',
'value' => date( 'Y-m-d H:i:s', current_time( 'timestamp' ) ),
'compare' => '>'
) );
return $args;
}
add_filter( 'display_posts_shortcode_args', 'be_dps_future_events', 10, 2 );
view raw functions.php hosted with ❤ by GitHub

Display Posts Shortcode

Bill Erickson

Bill Erickson is a freelance WordPress developer and a contributing developer to the Genesis framework. For the past 14 years he has worked with attorneys, publishers, corporations, and non-profits, building custom websites tailored to their needs and goals.

Ready to upgrade your website?

I build custom WordPress websites that look great and are easy to manage.

Let's Talk