In my WordPress v6.0.2, I have a custom taxonomy country
and a custom post_type interest
.
With post_type_link
filter (another working function) and with the below function, I am rewriting custom post_type URLs as https://www.example.com/country_name/interest_term
:
add_filter('generate_rewrite_rules', 'country_cpt_generating_rule');
function country_cpt_generating_rule($wp_rewrite) {
$rules = array();
$terms = get_terms(array(
'taxonomy' => 'country',
'hide_empty' => false,
));
$post_type = 'interest';
foreach ($terms as $term) {
$rules[$term->slug . '/interest/([^/]*)$'] = 'index.php?interest=$matches[1]&post_type=' . $post_type . 'name=$matches[1]';
}
$wp_rewrite->rules = $rules + $wp_rewrite->rules;
}
While I have single-interest.php
custom post_type template to show custom content, single posts are redirecting to home page with error404
class added to the body.
A var_dump(get_queried_object());
returning null
.
I have flushed permalinks and also tried checking is_singular()
to template redirecting, that did not worked.
How can I have a custom page template for single-interest
with above custom URL?