Posted on

The Events Calendar: The event search

The event search from The Events Calendar does not work when Relevanssi is enabled. In regular use, it works, but if you try to access the event list directly with a search term in the URL, the search finds nothing.

One solution is to make Relevanssi index the tribe_events post type. Then you can enable Relevanssi in the event search by adding this snippet to your site:

add_action( 'pre_get_posts', function( $q ) {
    if ( isset( $q->query_vars['post_type'] ) && 'tribe_events' === $q->query_vars['post_type'] ) {
        $q->set( 'relevanssi', true );
    }
} );

This function will turn Relevanssi on in all searches for the tribe_events posts.

Another approach is not to index the tribe_events post type. Instead, you can add this filter function:

add_filter( 'relevanssi_prevent_default_request', function( $prevent, $query ) {
    if ( isset( $query->query_vars['post_type'] ) && 'tribe_events' === $query->query_vars['post_type'] ) {
        $prevent = false;
    }
    return $prevent;
}, 10, 2 );

This function will stop Relevanssi from interfering with The Events Calendar search. There’s a bug in the current version of Relevanssi (2.18.0 for Premium, 4.16.0 for free version): if you have enabled Relevanssi in admin searches, the event search won’t work. Disable Relevanssi in admin searches to make the search function.

Leave a Reply

Are you a Relevanssi Premium customer looking for support? Please use the Premium support form.

Your email address will not be published.