Note: You are viewing the documentation for Version 3View Version 4 Docs


View the installation guide, browse the Knowledge Base, find out about SearchWP's many hooks, get support

The Events Calendar – Hide Past Events

Telling SearchWP to exclude past events from The Events Calendar is easily accomplished by taking advantage of the searchwp_exclude hook.

Adding this snippet to your theme’s functions.php will prevent SearchWP from including past events in search results:

function my_find_expired_events( $ids ) {
$args = array(
'post_type' => 'tribe_events',
'nopaging' => true,
'fields' => 'ids',
'meta_query' => array(
'key' => '_EventEndDate',
'value' => date( 'Y-m-d H:i:s' ),
'compare' => '<',
'type' => 'DATETIME',
$expired_events = get_posts( $args );
$ids = array_merge( $ids, $expired_events );
$ids = array_map( 'absint', $ids );
$ids = array_unique( $ids );
return $ids;
add_filter( 'searchwp_exclude', 'my_find_expired_events' );
view raw functions.php hosted with ❤ by GitHub

This hook is applied when searches are run, so it will automatically exclude past events based on the time the search takes place, there is no maintenance required.

Fix keyword search on your site. No coding required!

Now you can utilize all of the content that's gone unrecognized by native WordPress keyword search instantly with SearchWP

Get SearchWP