<?php
/**
* The Events Calendar: Redirect all site searches to be Tribe Bar Keyword searches.
*
* Should only be used if you want only Event posts to appear in general search
* queries. Again, Posts, Pages, and custom post types allowed to appear in
* search results will no longer be included--ONLY Events will appear.
* Example redirect:
* From: http://example.dev/?s=Weekly+Screening
* To: http://example.dev/events/?tribe-bar-search=Weekly%20Screening
*
* @link https://gist.github.com/cliffordp/23536ca604bca074a9d2f169277cfe59
* @link https://gist.github.com/cliffordp/51586f8c6f98ed9e1e1f2adbdd1dcb0a Similar snippet but for Post Tags (requires Filter Bar).
*/
add_action( 'template_redirect', 'cliff_redirect_site_search_to_tribe_bar_search' );
function cliff_redirect_site_search_to_tribe_bar_search() {
if (
! is_search() // is FALSE for Tribe Bar searches
|| ! function_exists( 'tribe_get_events_link' )
) {
return;
}
$url = add_query_arg( 'tribe-bar-search', get_search_query( false ), tribe_get_events_link() );
wp_redirect( esc_url_raw( $url ) );
exit;
}