Show Event Dates in Search Results
Adds the event's date (and venue when there is one) in front of its excerpt in search results, so visitors can tell upcoming events from old ones before clicking.
Opens WPIDE on
Code
add_filter( 'get_the_excerpt', function ( $excerpt, $post ) {
if ( ! is_search() || ! $post || 'tribe_events' !== $post->post_type || ! function_exists( 'tribe_get_start_date' ) ) {
return $excerpt;
}
$venue = function_exists( 'tribe_get_venue' ) ? tribe_get_venue( $post->ID ) : '';
$meta = tribe_get_start_date( $post, false ) . ( $venue ? ' · ' . $venue : '' );
return '[' . wp_strip_all_tags( $meta ) . '] ' . $excerpt;
}, 20, 2 );
Notes
Only affects events; other results keep their usual excerpt.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.