WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've created a custom post type and custom taxonomy (all fine so far!) but when I try to view the post it's giving me a page not found.

What do I need to do to setup a template which the custom post type below will use?

add_action( 'init', 'create_post_type' );
function create_post_type() {
    register_post_type( 'members',
            'labels' => array(
                'name' => __( 'Members' ),
                'singular_name' => __( 'Members' )
        'capability_type' => 'post',
        'supports' => array('title','editor','comments'),   
        'public' => true,
        'has_archive' => true,
        'rewrite' => array( 'slug' => 'members' ),

function members_init() {
    // create a new taxonomy    
            'label' => __( 'Member Categories' ),
            'sort' => true,
            'hierarchical' => true,
            'args' => array( 'orderby' => 'term_order' ),
            'rewrite' => array( 'slug' => 'members' )

add_action( 'init', 'members_init' );
share|improve this question
up vote 2 down vote accepted

According to the WordPress template hierarchy, a custom post type 'my-cpt' will first try to use single-my-cpt, then single.php and then index.php. The above issue is not caused by templates - indeed 404s are used when the content, not the template, cannot be found.

You are using a custom rewrite:

'rewrite' => array( 'slug' => 'members' )

For WordPress to recognise this you'll need to flush your rewrite rules by visiting the Settings > Permalink page.

share|improve this answer
Thanks, flushing the permalinks (I always forget to do that!!) worked. So if I create a template called single-members.php that should work? It's now showing a template just not sure what one! – Rob Apr 4 '12 at 11:16
If you create single-members.php it will use that, if not it will use single.php. In the unlikely case that doesn't exist either it will use index.php. – Stephen Harris Apr 4 '12 at 11:22

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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