Skip to content

Instantly share code, notes, and snippets.

@vicskf
Created April 21, 2017 04:08
Show Gist options
  • Save vicskf/490fc3ff0c8f63e255ff2fbbfa8ae963 to your computer and use it in GitHub Desktop.
Save vicskf/490fc3ff0c8f63e255ff2fbbfa8ae963 to your computer and use it in GitHub Desktop.
Does not show past events from The Events Calendar
<?php
/*
* Does not show past events from The Events Calendar
*/
add_filter('tribe_events_pre_get_posts', 'filter_tribe_all_occurences', 100);
function filter_tribe_all_occurences ($wp_query) {
if ( !is_admin() ) {
$new_meta = array();
$today = new DateTime();
// Join with existing meta_query
if(is_array($wp_query->meta_query))
$new_meta = $wp_query->meta_query;
// Add new meta_query, select events ending from now forward
$new_meta[] = array(
'key' => '_EventEndDate',
'type' => 'DATETIME',
'compare' => '>=',
'value' => $today->format('Y-m-d H:i:s')
);
$wp_query->set( 'meta_query', $new_meta );
}
return $wp_query;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment