This is pretty straightforward using a rewrite endpoint.
The first step is to set an ep_mask
when you register your taxonomy, which is part of the rewrite
argument. Note that it’s a constant, and should be as-is, without quotes:
$args = array(
'rewrite' => array(
'slug' => 'location',
'with_front' => false,
'ep_mask' => EP_TAGS
),
// your other args...
);
Now you can add a rewrite endpoint immediately after registering your taxonomy, also hooked to init
:
add_rewrite_endpoint( 'overview', EP_TAGS );
Don’t forget to flush rewrite rules after adding or changing anything in this code. You can do this quickly by visiting the Settings > Permalinks page.
Now you’ll be able to visit
domain.com/location/england/
as well as
domain.com/location/england/overview/
To load a different template for these requests, we can use the taxonomy_template
filter:
function wpd_location_overview_template( $template ){
if( false !== get_query_var( 'overview', false ) ){
$template = locate_template( 'location-overview.php' );
}
return $template;
}
add_filter( 'taxonomy_template', 'wpd_location_overview_template' );
This will load location-overview.php
from your child or parent theme whenever overview
is in the URL.
Use get_queried_object_id()
or get_queried_object()
in the template to fetch your fields associated to this term. The main query will also still contain the posts for this term, if you have any use for them.