Skip to content

Instantly share code, notes, and snippets.

@cliffordp
Last active August 23, 2018 05:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cliffordp/51586f8c6f98ed9e1e1f2adbdd1dcb0a to your computer and use it in GitHub Desktop.
Save cliffordp/51586f8c6f98ed9e1e1f2adbdd1dcb0a to your computer and use it in GitHub Desktop.
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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment