0

The story goes that you cannot have by default the same CPT slug as the page you need to create for your CPT. On a few occasions I've been able to do just that though and have it work just fine. For example:

I create my CPT

register_post_type('schedule', array(
        'labels'            =>  array(
            'name'          =>      __('Events'),
            'singular_name' =>      __('Event'),
            'all_items'     =>      __('View Events'),
            'add_new'       =>      __('New Event'),
            'add_new_item'  =>      __('New Event'),
            'edit_item'     =>      __('Edit Event'),
            'view_item'     =>      __('View Event'),
            'search_items'  =>      __('Search Events'),
            'no_found'      =>      __('No Eventss Found'),
            'not_found_in_trash' => __('No Events in Trash')
                                ),
        'public'            =>  true,
        'publicly_queryable'=>  true,
        'show_ui'           =>  true, 
        'query_var'         =>  true,
        'show_in_nav_menus' =>  false,
        'rewrite'           =>  array('slug' => 'schedule', 'with_front' => false),
        'capability_type'   =>  'post',
        'hierarchical'      =>  false,
        'menu_position'     =>  21,
        'supports'          =>  array('title','editor', 'thumbnail'),
        'has_archive'       =>  false
    ));

I have my CPT Page:

Custom Post Type Page - With Same Slug

My permalink structure is: /press-releases/%year%/%monthnum%/%day%/%postname%/

Finally I have a page template called "page-schedule.php" where I then query my CPT and display it just fine, even paged. I'm not the only one who's been able to do this as I have seen a few posts on wordpress.org forums claiming to also have been able to do this.

My question is, what exactly causes this to happen and how can it be reproduced so I can achieve nice CPT permalink structures without plugins?

1 Answer 1

1

There's nothing magical about it, your post type doesn't have an archive ( has_archive is false ), so there's no rewrite rule for your post type that matches just /%post_type%/, the only existing rules for your post type are for /%post_type%/%some_other_thing%/, so there's no clash with your page.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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