Question

WordPress is 404ing all of my Custom Post Type posts. Have I missed a step here?

I’m using the following to set up my CPT:

function custom_post_types() {  
  register_post_type(
    'creativework',
    array(
      'labels' => array(
        'name' => _x('Works', 'post type general name'),
        'singular_name' => _x('Work', 'post type singular name'),
        'add_new' => _x('Add New', 'Work'),
        'add_new_item' => __('Add New Work'),
        'edit_item' => __('Edit Work'),
        'new_item' => __('New Work'),
        'all_items' => __('All Works'),
        'view_item' => __('View Work'),
        'search_items' => __('Search Works'),
        'not_found' =>  __('No Works found'),
        'not_found_in_trash' => __('No Works found in Trash'), 
        'parent_item_colon' => '',
        'menu_name' => __('Works')
      ),
      'public' => true,
      'menu_position' => 5,
      //'rewrite' => array('slug' => 'work'),
      'supports' => array('title', 'editor', 'thumbnail'),
      'has_archive' => 'true'
    )
  );
}

add_action( 'init', 'custom_post_types' );

I originally had an underscore in the type (creative_work), rewriting the slug to just be “work”, but I had no idea which permutation WordPress would use to find the template—I tried file names like single-creative_work.php, single-creativework.php, single-work.php, all under themes/roots/ (I was using Roots as a baseline theme), with the contents:

<?php get_template_part('templates/content', 'work'); ?>

But themes/roots/templates/content-work.php was never displayed. Instead it seemed that themes/roots/page.php was being served up? When I manually edited page.php to get_template_part('templates/content', 'work') as a test, it seemingly used the template I wanted but then it had the post ID or something wrong where it was displaying the homepage for ANYTHING under website.com/creativework/.

In an attempt to eliminate all possible conflicts, I deactivated Roots in favor of Twentythirteen, and disabled all plugins except one, the one I wrote to set up the CPT (code at the top). Now, whenever I hit website.com/creativework/ or website.com/creativework/post-title (following the permalink from “View Work” in the post editor, or in Search results), I get a 404 instead of the homepage, despite both single-creativework.php and archive-creativework.php existing under themes/twentythirteen.

EDIT: website.com/?creativework=post-title, however, works.

I am hopelessly confused by all this. What is the correct, foolproof way to set up a custom post type template, step-by-step? Ideally I want to know how to do this in Roots, but for now I will settle on just how to get it working at all.

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with wordpress.stackexchange
scroll top