admin管理员组文章数量:1295927
I need to remove the parent slug in the permalink of a child post. The child post is of a different cpt than the parent post. So I get:
example/parentcpt/parent-post-name/child-post-name //which results to a 404.
I need
example/child-post-name
or:
example/childcpt/child-post-name
Switching between permalink structures doesnt help either. Ive tried a number of plugins but they dont solve. Adding the following doesnt help:
'rewrite' => array('slug' => false, 'with_front' => false)// register_post_type function
Someone help please ... :)
I need to remove the parent slug in the permalink of a child post. The child post is of a different cpt than the parent post. So I get:
example/parentcpt/parent-post-name/child-post-name //which results to a 404.
I need
example/child-post-name
or:
example/childcpt/child-post-name
Switching between permalink structures doesnt help either. Ive tried a number of plugins but they dont solve. Adding the following doesnt help:
'rewrite' => array('slug' => false, 'with_front' => false)// register_post_type function
Someone help please ... :)
Share Improve this question asked Mar 7, 2013 at 14:38 TimothyTimothy 1332 silver badges6 bronze badges1 Answer
Reset to default 2I was able to solve this problem by adding the code below under my theme/functions.php file. (My custom post type slug is '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');
本文标签: permalinksRemoving parent slug in hierachial custom post type
版权声明:本文标题:permalinks - Removing parent slug in hierachial custom post type 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741626269a2389101.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论