This bothered me for way too long before actually discovering the solution. The solution is written there in plain English within the register_post_type array, yet I didn’t think to fiddle with it.
The problem was regardless of permalinks settings, my single custom post type would always 404. It didn’t matter if I used the default single.php or single-locations.php (my custom post type is called ‘locations’).
After some Googling I found these useful link which are a useful bookmark for future reference:
Here’s the Codex page for registering a custom post type:
Here’s my arguments array ready to register the post type:
$args = array( 'label' => 'Locations', 'description' => 'Location', 'labels' => $labels, 'hierarchical' => true, 'public' => true, 'show_ui' => true, 'show_in_menu' => true, 'show_in_nav_menus' => true, 'show_in_admin_bar' => true, 'menu_position' => 5, 'can_export' => true, 'has_archive' => true, 'exclude_from_search' => false, 'publicly_queryable' => true, // NOTE: this NEEDS to be true or it will 404 'supports' => array( 'page-attributes', 'title', 'editor', 'excerpt', 'thumbnail' // TODO add theme support for post-thumbnails ), );
Notice the following line:
'publicly_queryable' => true
If this false then your custom post type will literally not be publically accessible. In plain English that just means that it’ll 404.
Hope this helps fix your problem. If you find a different solution that helps, please let me know in the comments.