admin管理员组文章数量:1130349
I have one page slug "new-site" also i have another custom post type with same slug "new-site" while i browse site then it directally goes to archive page and show all the posts from CPT new site.
How can i solve if i open with this url to page and for cpt post detail.
Thanks
I have one page slug "new-site" also i have another custom post type with same slug "new-site" while i browse site http://example/new-site then it directally goes to archive page and show all the posts from CPT new site.
How can i solve if i open with this url to page http://example/new-site and http://example/new-site/post-slug for cpt post detail.
Thanks
Share Improve this question asked Mar 8, 2016 at 7:42 PusPus 1034 bronze badges 2- And the archive of CPT? Do you want it? – cybmeta Commented Mar 8, 2016 at 7:52
- I dont need archive CPT, i just need to open page while i enter example/new-site and i need CPT single page while i open example/new-site/post-slug – Pus Commented Mar 8, 2016 at 7:54
1 Answer
Reset to default 2As you don't need the CPT archvie, the easiest way to use example/new-site to open a page, and example/new-site/post-slug to open single posts of "new-site" post type, is to declare has_archive => false when registering the CPT:
add_action( 'init', 'cyb_register_cpt' );
function cyb_register_cpt() {
$args = array(
// .....
'has_archive' => false
);
register_post_type( 'new-site', $args );
}
PD: Remember to flush the rewrite rules:
add_action( 'init', 'cyb_register_cpt' );
function cyb_register_cpt() {
$args = array(
// .....
'has_archive' => false
);
register_post_type( 'new-site', $args );
}
register_activation_hook( __FILE__, function () {
cyb_register_cpt();
flush_rewrite_rules();
} );
register_deactivation_hook( __FILE__, function () {
flush_rewrite_rules();
} );
I have one page slug "new-site" also i have another custom post type with same slug "new-site" while i browse site then it directally goes to archive page and show all the posts from CPT new site.
How can i solve if i open with this url to page and for cpt post detail.
Thanks
I have one page slug "new-site" also i have another custom post type with same slug "new-site" while i browse site http://example/new-site then it directally goes to archive page and show all the posts from CPT new site.
How can i solve if i open with this url to page http://example/new-site and http://example/new-site/post-slug for cpt post detail.
Thanks
Share Improve this question asked Mar 8, 2016 at 7:42 PusPus 1034 bronze badges 2- And the archive of CPT? Do you want it? – cybmeta Commented Mar 8, 2016 at 7:52
- I dont need archive CPT, i just need to open page while i enter example/new-site and i need CPT single page while i open example/new-site/post-slug – Pus Commented Mar 8, 2016 at 7:54
1 Answer
Reset to default 2As you don't need the CPT archvie, the easiest way to use example/new-site to open a page, and example/new-site/post-slug to open single posts of "new-site" post type, is to declare has_archive => false when registering the CPT:
add_action( 'init', 'cyb_register_cpt' );
function cyb_register_cpt() {
$args = array(
// .....
'has_archive' => false
);
register_post_type( 'new-site', $args );
}
PD: Remember to flush the rewrite rules:
add_action( 'init', 'cyb_register_cpt' );
function cyb_register_cpt() {
$args = array(
// .....
'has_archive' => false
);
register_post_type( 'new-site', $args );
}
register_activation_hook( __FILE__, function () {
cyb_register_cpt();
flush_rewrite_rules();
} );
register_deactivation_hook( __FILE__, function () {
flush_rewrite_rules();
} );
本文标签: rewrite rulesWordpress CPT slug and page slug conflicts
版权声明:本文标题:rewrite rules - Wordpress CPT slug and page slug conflicts 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749190750a2330149.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论