我需要删除子帖子永久链接中的父段塞。子帖子与父帖子的cpt不同。所以我得到:
example.com/parentcpt/parent-post-name/child-post-name //which results to a 404.
我需要
example.com/child-post-name
或:
example.com/childcpt/child-post-name
在permalink结构之间切换也无济于事。我尝试了很多插件,但都解决不了问题。添加以下内容没有帮助:
\'rewrite\' => array(\'slug\' => false, \'with_front\' => false)// register_post_type function
请有人帮忙……:)
SO网友:Tim Truston
通过在我的主题/函数下添加下面的代码,我能够解决这个问题。php文件。(我的自定义帖子类型slug是“news”)
function df_custom_post_type_link( $post_link, $id = 0 ) {
$post = get_post($id);
if ( is_wp_error($post) || \'news\' != $post->post_type || empty($post->post_name) )
return $post_link;
return home_url(user_trailingslashit( "$post->post_name" ));
}
add_filter( \'post_type_link\', \'df_custom_post_type_link\' , 10, 2 );
function df_custom_rewrite_rule() {
add_rewrite_rule(\'(.*?)$\', \'index.php?news=$matches[1]\', \'top\');
}
add_action(\'init\', \'df_custom_rewrite_rule\');