Last active
July 21, 2020 15:01
-
-
Save jmarchwinski/72418a6a2c3c48dea9bea6f974ac00d4 to your computer and use it in GitHub Desktop.
Hide past events from wordpress search
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Exclude past events from search | |
function mySearchFilter($query) { | |
if ($query->is_search) { | |
$past_events = tribe_get_events( array( | |
'posts_per_page' => -1, | |
'end_date' => new DateTime() | |
) ); | |
$exclude_events = []; | |
foreach ( $past_events as $past_event ) { | |
$exclude_events[] = $past_event->ID; | |
} | |
$query->set('post__not_in', $exclude_events); | |
} | |
return $query; | |
} | |
add_filter('pre_get_posts','mySearchFilter'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment