我已经为此挣扎了几个小时了。
我正在尝试获取此URL结构:example.com/business/%custom-tax-name%/%custom-post-name%/
我所说的海关税名称不是指分类法的名称(“位置”),而是指为特定职位选择的值,即城市名称。所以,example.com/business/long-island-city/business-name
或example.com/business/phoenix/business-name/
到目前为止,我已经制定了自定义分类法:
$singular = \'Merchant Location\';
$plural = \'Merchant Locations\';
$taxonomy_args = array(
\'rewrite\' => array(
\'slug\' => \'business-location\',
\'with_front\' => FALSE,
\'hierarchical\' => FALSE
)
);
// Register taxonomy ...
并更改了post_type_link
滤器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);
在那之后,得到的URL很好,这正是我想要的,所以过滤器功能工作得很好。但是,当我单击URL时,它会转到以下位置:example.com/business/long-island-city/long-island-city/business-name
生成404。
这可能是什么原因造成的,我如何修复它?
非常感谢您的帮助。
Note:
我不想要这样的URL结构:example.com/business/location/long-island-city/business-name/
在URL中具有分类名称。