Use a Dynamic Template for The Events Calendar Category Archives
Note: This snippet relies on filters from The Events Calendar plugin. If a future version of the plugin changes or removes these filters, the snippet may stop working.
The snippet can be used to override the Tribe Events Calendar category archives with a Total dynamic template.
To use it:
- Create a dynamic template under Theme Panel > Dynamic Templates.
- Replace
$template_id = 170;in the snippet with your template's ID. - Use the Post Cards element in your Dynamic Template, with its Query Type to Auto so it shows events from the current category.
// Stops the Events Calendar from rendering event category archives, so the theme template loads instead.
add_filter( 'tribe_events_views_v2_bootstrap_pre_should_load', function( $should_load, $query ) {
if ( $query instanceof WP_Query && $query->is_main_query() && $query->is_tax( 'tribe_events_cat' ) ) {
return false;
}
return $should_load;
}, 10, 2 );
// Stops the Events Calendar from replacing the category archive query with a placeholder page.
add_filter( 'tribe_events_views_v2_should_hijack_page_template', function( $should_hijack, $query ) {
if ( $query instanceof WP_Query && $query->is_tax( 'tribe_events_cat' ) ) {
return false;
}
return $should_hijack;
}, 10, 2 );
// Uses dynamic template 170 for event category archives.
add_filter( 'totaltheme/theme_builder/location_template_id', function( $template_id, $location ) {
if ( 'archive' === $location && is_tax( 'tribe_events_cat' ) ) {
$template_id = 170;
}
return $template_id;
}, 10, 2 );
// Stops dynamic template elements from using the main Events page on event category archives.
add_filter( 'wpex_get_dynamic_post_id', function( $post_id ) {
if ( is_tax( 'tribe_events_cat' ) ) {
return 0;
}
return $post_id;
} );
// Uses the category name as the title on event category archives.
add_filter( 'wpex_title', function( $title ) {
if ( is_tax( 'tribe_events_cat' ) ) {
$title = single_term_title( '', false );
}
return $title;
}, 20 );All PHP snippets should be added via child theme's functions.php file or via a plugin.
We recommend Code Snippets (100% Free) or WPCode (sponsored)
We recommend Code Snippets (100% Free) or WPCode (sponsored)
Related Snippets