Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save barryhughes/51e192c60b86be32adb5630cdb8ece19 to your computer and use it in GitHub Desktop.
Save barryhughes/51e192c60b86be32adb5630cdb8ece19 to your computer and use it in GitHub Desktop.
Remove events (from the upcoming events list) that have already started | TEC 4.6.x
<?php
/**
* "Filter out" events that have already started from list view.
*
* This deviates from the default behaviour which will include events
* that started in the past but are ongoing (have not yet ended).
*/
add_filter( 'posts_where', function( $sql, $query ) {
global $wpdb;
if ( 'list' !== $query->get( 'eventDisplay' ) ) {
return $sql;
}
$start_field = "{$wpdb->postmeta}.meta_value";
$start_date = esc_sql( $query->get( 'start_date' ) );
return "$sql AND $start_field > '$start_date' ";
}, 1000, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment