Skip to content

Instantly share code, notes, and snippets.

@billerickson
Last active June 27, 2022 16:57
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save billerickson/2a1c2c4ee4d622f4633048529ceb8931 to your computer and use it in GitHub Desktop.
Save billerickson/2a1c2c4ee4d622f4633048529ceb8931 to your computer and use it in GitHub Desktop.
<?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 );
@carljbusch
Copy link

Is there a way to display the event start date?

@KZeni
Copy link

KZeni commented Jun 27, 2022

There is an important typo in the snippet as of writing! Unless/until the item below is addressed, this snippet won't actually do anything.

if( 'tribe_events' != $args['post_type'] ) (at the start of the function) needs to be if( 'tribe_events' != $atts['post_type'] ) (effectively swap $args for $atts) since we're checking the shortcode attributes & not the query arguments for what post type has been specified (which it then proceeds to adjust the $args for the query accordingly if the post type specified via the shortcode's attributes is tribe_events.)

@KZeni
Copy link

KZeni commented Jun 27, 2022

@carljbusch

Is there a way to display the event start date?

I know this is late, but this might still be helpful for others.

I use the following (or similar) for that sort of thing: https://gist.github.com/KZeni/1c9d2204f553457a8b034696d4e472ec

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment