I am trying to create custom end point for the custom taxonomy - 'species'
I am trying to use urls like
https://example.com/dogs/shop/
https://example.com/cats/shop/
https://example.com/dogs/services/
https://example.com/cats/services/
https://example.com/dogs/sales
https://example.com/cats/sales
where dogs, cats is taxonomy term
Following is the code
function my_register_my_taxes_species() {
add_rewrite_endpoint( 'shop', EP_PAGES );
add_rewrite_endpoint( 'services', EP_PAGES );
add_rewrite_endpoint( 'sales', EP_PAGES );
add_filter('request', function($vars) {
if (isset($vars['shop'])) {
$vars['shop'] = true;
}
if (isset($vars['services'])) {
$vars['services'] = true;
}
if (isset($vars['sales'])) {
$vars['sales'] = true;
}
return $vars;
});
add_filter('template_include', function($template) {
if (is_tax('species') && get_query_var('shop')) {
$post = get_queried_object();
$end_template = plugin_dir_path( __FILE__ ) . 'templates/shop.php';
return $end_template;
}
if (is_tax('species') && get_query_var('services')) {
$post = get_queried_object();
$end_template = plugin_dir_path( __FILE__ ) . 'templates/services.php';
return $end_template;
}
if (is_tax('species') && get_query_var('sales')) {
$post = get_queried_object();
$end_template = plugin_dir_path( __FILE__ ) . 'templates/sales.php';
return $end_template;
}
return $template;
});
$args = [
"label" => __( "Species", "hello-elementor-child" ),
"public" => true,
"publicly_queryable" => true,
"hierarchical" => true,
"rewrite" => [ 'slug' => 'species', 'with_front' => true,'ep_mask'=> EP_PAGES, 'hierarchical' => true ],
];
register_taxonomy( "species", [ "job_listing", "product" ], $args );
}
add_action( 'init', 'my_register_my_taxes_species' );
This code above works fine upto one endpoint but not working for multiple endpoints like following
https://example.com/dogs/shop/prod-cat1
https://example.com/dogs/shop/prod-cat2
https://example.com/cats/shop/prod-cat1
https://example.com/cats/shop/prod-cat2
Uses template shop-cat.php & value of query variable i.e prod-cat1, prod-cat2 available on template
https://example.com/dogs/services/sr1
https://example.com/dogs/services/sr2
https://example.com/cats/services/sr3
https://example.com/cats/services/sr4
Uses template services-cat.php & value of query variable i.e sr1, sr2 available on template
https://example.com/dogs/sales/sl1
https://example.com/dogs/sales/sl2
https://example.com/cats/sales/sl3
https://example.com/cats/sales/sl4
uses template sales-cat.php & value of query variable i.e sl1, sl2 available on template
How can I create multiple endpoints and the assign templates and use the query variables