Why isn’t Post Type Templates working for me?

So, according to this page, it states:

single-{post_type}.php
If your custom post type were ‘product’, and/or query_var = “product”, WordPress would look for single-product.php to display the
single or permalink of the post.

Read More

So I have this code in my functions.php:

register_post_type( 'project',$args);

And I have this template: single-project.php

Then why isn’t my custom post using this template?

update
Using get_post_types() I can see that my post type is not listed. If it is not registered, then why can I create and delete custom posts?

add_action('after_setup_theme','init_setup');

function init_setup() {
  add_action( 'init', 'create_post_type' );
}

function create_post_type() {
  $args = array(
    'labels' => array(
      'name' => __( 'Prosjekter' ),
      'singular_name' => __( 'Prosjekt' ),
      'add_new' => __('Nytt prosjekt')
    ),
    'public' => true,
        'show_ui' => true,
        'show_in_menu' => true,
    'has_archive' => false,
    'taxonomies' => array('category'),
    'menu_position' => 5,
    'supports' => array( 'title', 'editor', 'thumbnail', 'page-attributes','post_tag' ),
    'rewrite' => array('slug' => 'prosjekt')
  );

  register_post_type( 'project',$args);
}

Related posts

Leave a Reply

1 comment

  1. From the Codex:

    register_post_type should only be invoked through the ‘init’ action.
    It won’t work at all if called before ‘init’, and aspects of the new
    post type will work incorrectly if called later.

    Have you tried registering it like so?

    add_action( 'init', 'create_post_type' ); // NOT inside `init_setup()`
    

    [edit]

    The only other thing I can think of is that since you’re using rewrite, you might want to flush the rewrite rules. Also from the Codex:

    Note: If registering a post type inside of a plugin, call
    flush_rewrite_rules() in your activation and deactivation hook (see
    Flushing Rewrite on Activation below). If flush_rewrite_rules() is not
    used, then you will have to manually go to Settings > Permalinks and
    refresh your permalink structure before your custom post type will
    show the correct structure.

    If you don’t want to fiddle with the flush_rewrite_rules() function at this moment, just go into Settings > Permalinks and re-save your permalink preferences.