Last active
August 23, 2018 05:15
-
-
Save cliffordp/23536ca604bca074a9d2f169277cfe59 to your computer and use it in GitHub Desktop.
The Events Calendar: Redirect all site searches to be Tribe Bar Keyword searches.
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
<?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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment