对我的本地开发人员进行了快速测试-https://pastebin.com/bP8byGHR - 查找评论// here
.
在你的分类法上,我不得不删除功能,因为它没有显示在我的菜单上,如果它对你有用,请忽略它,但我看不到它的任何用例。
您的重写是问题所在,您可以使用post_type_link
:
add_filter(\'post_type_link\', \'so_update_permalink_structure\', 10, 2);
function so_update_permalink_structure( $post_link, $post )
{
if ( false !== strpos( $post_link, \'%community_post_domain%\' ) ) {
$taxonomy_terms = get_the_terms( $post->ID, \'community_post_domain\' );
foreach ( $taxonomy_terms as $term ) {
if ( ! $term->parent ) {
$post_link = str_replace( \'%community_post_domain%\', $term->slug, $post_link );
}
}
}
return $post_link;
}
别忘了冲洗permalinks并进行测试。
通过快速搜索,我找到了一篇解释得比我好得多的博客文章,它对您的案例很有用:https://react2wp.com/using-same-slug-for-custom-post-type-and-custom-taxonomy/
edit: 我的permalinks测试:
// Created a page with the same slug
// Test url: ok
url.test/community/
// Created the taxonomy \'kubernetes\'
// Test url: ok
url.test/community/kubernetes/
// Created a new cpt post
// Post with a taxonomy: ok
url.test/community/kubernetes/go-micro-services/
// Post without a taxonomy: error 400
// For this case you should set a default taxonomy to prevent an error
url.test/community/%community_post_domain%/go-micro-services/