-
-
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 ); |
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.)
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
Is there a way to display the event start date?