I registered a custom post type with the following code:
#Register custom post type for Stars of the Month
add_action( 'init', 'sdp_create_star_type' );
function sdp_create_star_type() {
register_post_type( 'sdp_star',
array(
'labels' => array(
'name' => __( 'Stars' ),
'singular_name' => __( 'Star' ),
'add_new_item' => 'Add New Star of the Month',
'edit_item' => 'Edit this Star',
'all_items' => 'All Stars'
),
'public' => true,
'has_archive' => true,
'rewrite' => array('slug' => 'stars'),
'menu_icon' => 'dashicons-star-filled',
'menu_position' => 5, //just below posts
'supports' => array('title', 'thumbnail')
)
);
//flush_rewrite_rules(); //<--This doesn't work either
}
I named the template my_theme/single-sdp_star.php
as per the WP naming conventions.
PROBLEM: No matter what I do, the wrong template file gets used: my_theme/single.php
.
I already tried re-saved the permalinks (many times) and this does not help.
What else could be I be missing?
I had the same problem. Why WordPress doesn’t automatically use the custom single.php template is above me. That aside, here is the code I’m using to force my CPT to use my custom single.php. Just change the CPT and template name to suite your needs.