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 Shortcode - Only query future events
*
* @author Bill Erickson
* @see
*
* @param array $args
* @param array $atts
* @return array $args
*/
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

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