Php 从自定义柱类型中移除段塞

Php 从自定义柱类型中移除段塞,php,wordpress,Php,Wordpress,这已经被问了很多次了,但是我尝试过的每一个解决方案都不适合我——我正在尝试删除自定义帖子类型的slug。我试过了 'with_front' => false, 但这对我也不起作用,它删除了管理区域(在我的例子中是“位置”)中永久链接中的slug,但是访问新链接时,我得到了404。我试过冲洗permalinks,但没用。但是,我仍然可以通过访问/位置/帖子名称访问帖子 我怎样才能解决这个问题?提前感谢。请尝试以下代码 function remove_custom_post_type_sl

这已经被问了很多次了,但是我尝试过的每一个解决方案都不适合我——我正在尝试删除自定义帖子类型的slug。我试过了

 'with_front' => false,
但这对我也不起作用,它删除了管理区域(在我的例子中是“位置”)中永久链接中的slug,但是访问新链接时,我得到了404。我试过冲洗permalinks,但没用。但是,我仍然可以通过访问/位置/帖子名称访问帖子

我怎样才能解决这个问题?提前感谢。

请尝试以下代码

function remove_custom_post_type_slug( $post_link, $post, $leavename ) {

    $post_link = str_replace( '/locations/', '/', $post_link );

    return $post_link;
}
add_filter( 'post_type_link', 'remove_custom_post_type_slug', 10, 3 );

尝试以下代码

function remove_custom_post_type_slug( $post_link, $post, $leavename ) {

    $post_link = str_replace( '/locations/', '/', $post_link );

    return $post_link;
}
add_filter( 'post_type_link', 'remove_custom_post_type_slug', 10, 3 );

谢谢您的回复,但我仍然会遇到与该代码相同的问题。我已经刷新了permalinks,仍然得到了404,没有/locations/但是可以导航到/locations/post name谢谢你的回复,但是我仍然得到了与代码相同的问题。我已经刷新了permalinks,但仍然得到了404,没有/locations/,但可以导航到/locations/post name