Skip to content

Instantly share code, notes, and snippets.

@adamcin
Created April 3, 2022 21:46
Show Gist options
  • Save adamcin/0e9b2dfc496540bc43a54b629fb6c994 to your computer and use it in GitHub Desktop.
Save adamcin/0e9b2dfc496540bc43a54b629fb6c994 to your computer and use it in GitHub Desktop.
Expired Event SearchWP query mod filter for Event Espresso
<?php
add_filter( 'searchwp\query\mods', function( $mods, $query ) {
global $wpdb;
$today = new DateTime(date('Y-m-d'));
$today = $today->format('Y-m-d H:i:s');
// Retrieve Source name to use with Mod.
$source = \SearchWP\Utils::get_post_type_source_name( 'espresso_events' );
$mod = new \SearchWP\Mod( $source );
$mod->set_local_table( EEM_Datetime::instance()->table() );
$mod->on( 'EVT_ID', [ 'column' => 'id' ] );
// more join filters here if necessary
$mod->raw_where_sql( function( $runtime_mod ) use ( $wpdb, $today ) {
return $wpdb->prepare( "{$runtime_mod->get_local_table_alias()}.DTT_EVT_end >= %s", $today );
} );
$mods[] = $mod;
return $mods;
}, 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment