I've been struggling with this for hours.
I'm trying to get this URL structure:
example.com/business/%custom-tax-name%/%custom-post-name%/
By custom tax name I don't mean the name of the taxonomy ("Location"), I mean the value that is chosen for that particular post, which will be a city name. So,
example.com/business/long-island-city/business-name
or
example.com/business/phoenix/business-name/
So far I've made a custom taxonomy:
$singular = 'Merchant Location';
$plural = 'Merchant Locations';
$taxonomy_args = array(
'rewrite' => array(
'slug' => 'business-location',
'with_front' => FALSE,
'hierarchical' => FALSE
)
);
// Register taxonomy ...
and have changed the links in the post_type_link
filter
function filter_business_permalinks($post_link, $post, $leavename, $sample) {
if ($post->post_type == 'my_custom_post_type') {
$terms = get_the_terms($post->ID, 'my_custom_taxonomy');
foreach ($terms as $term) {
$post_link = str_replace('business/', 'business/'. $term->slug .'/', $post_link);
break;
}
return $post_link;
}
add_filter('post_type_link', 'filter_business_permalinks', 10, 4);
And the resulting URL is fine after that, just what I wanted, so the filter function is working perfectly. However when I click the URL, it goes to this:
example.com/business/long-island-city/long-island-city/business-name
which yields a 404.
What could be causing this and how could I fix it?
All help is greatly appreciated.
Note:
What I don't want is a URL structure like this:
example.com/business/location/long-island-city/business-name/
having the taxonomy name in the URL.