Last active
November 9, 2021 22:06
-
-
Save pixelwatt/79788edfedc91d0aba29980876121d97 to your computer and use it in GitHub Desktop.
Exclude past events from Modern Tribe's Events Calendar plugin when rebuilding Relevanssi's search index
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
add_filter('relevanssi_do_not_index', 'mytheme_noindex_old_events', 10, 2); | |
function mytheme_noindex_old_events($block, $post_id) { | |
$events_to_exclude; | |
$result = wp_cache_get( 'old_events' ); | |
if ( false === $result ) { | |
$events = tribe_get_events( array( | |
'start_date' => date( 'Y-m-d H:i:s', strtotime( '-5 years' ) ), | |
'end_date' => date( 'Y-m-d H:i:s', strtotime( '-1 day' ) ), | |
'eventDisplay' => 'custom', | |
'posts_per_page' => 99999 | |
)); | |
foreach ($events as $event) { | |
$events_to_exclude[] = $event->ID; | |
} | |
$result = $events_to_exclude; | |
wp_cache_set( 'old_events', $result ); | |
} | |
if (in_array($post_id, $result)) $block = true; | |
return $block; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment