Skip to content

Instantly share code, notes, and snippets.

@erishel
Created May 11, 2018 18:29
Show Gist options
  • Save erishel/e96ee07dfab69bde8c6a0250ea06de02 to your computer and use it in GitHub Desktop.
Save erishel/e96ee07dfab69bde8c6a0250ea06de02 to your computer and use it in GitHub Desktop.
TEC - Hide past events
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