The Events Calendar - Filter Bar: Redirect all Post Tags to their Event view.
<?php
/**
* The Events Calendar - Filter Bar: Redirect all Post Tags to their Event view.
*
* Does not work if Filter Bar is not active. Should only be used if you use
* Post Tags *solely* for Events and not for Posts. Example redirect:
* From: http://example.dev/tag/around-the-house/
* To: http://example.dev/events/?tribe_tags[]=53
*
* @link https://gist.github.com/cliffordp/51586f8c6f98ed9e1e1f2adbdd1dcb0a
* @link https://gist.github.com/cliffordp/23536ca604bca074a9d2f169277cfe59 Similar snippet but for general site searches to Tribe Bar search (does not require Filter Bar).
*/
add_action( 'template_redirect', 'cliff_redirect_post_tag_to_events_tag_view' );
function cliff_redirect_post_tag_to_events_tag_view() {
if (
! is_tag()
|| ! function_exists( 'tribe_get_events_link' )
|| ! class_exists( 'Tribe__Events__Filterbar__View' )
) {
return;
}
$tag_object = get_queried_object();
$url = add_query_arg( 'tribe_tags[]', $tag_object->term_id, tribe_get_events_link() );
wp_redirect( esc_url_raw( $url ) );
exit;
}