我有一个帖子类型location
其中包含2种分类法-service
&;sector
. 现在,wordpress通常会显示permalink,如-site_url/location/post_name
我成功地展示了-site_url/service_slug/sector_slug/post_name
这正是我想要的,我已经做到了。问题是,它破坏了所有页面的url!示例:我有一个联系人页面siteurl/contact
. 现在,当我转到联系人页面url时,它显示为404。这意味着permalink结构可以与我的location
但它打破了我所有的页面永久链接。
我已将wordpress permalink结构更新为/%postname%/
好几次。
下面是我的代码-
位置post类型重写段塞-
\'rewrite\' = array(
\'slug\' => \'%sector%/%service%\',
\'with_front\' => true
);
*我也尝试过“with\\u front”false,同样的事情。用于更新slug的自定义函数-
function rewrite_location_post_slug( $post_link, $id = 0 ){
$post = get_post($id);
if ($post->post_type == \'location\'){
$terms_service = wp_get_object_terms( $post->ID, \'service\' );
$terms_sector = wp_get_object_terms( $post->ID, \'sector\' );
if( $terms_service && $terms_sector){
$sector_replaced = str_replace( \'%sector%\' , $terms_sector[0]->slug , $post_link );
return str_replace( \'%service%\' , $terms_service[0]->slug , $sector_replaced );
}
} else {
return $post_link;
}
}
add_filter( \'post_type_link\', \'rewrite_location_post_slug\', 1, 3 );
分类法的代码中没有任何重写段塞。此处为完整代码-https://pastebin.com/3eLZhga2这是wordpress的bug还是我遗漏了什么?请告知。