0

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.com/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.com/new-site and http://example.com/new-site/post-slug for cpt post detail.

Thanks

2

As you don't need the CPT archvie, the easiest way to use example.com/new-site to open a page, and example.com/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();
} );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.