Wordpress custom template not showing in custom post type
php, templates, wordpress
Solution
You cannot have page templates of any Wordpress template files:
Like:
archive-*.php
category-*.php
single-*.php // in your case
or any other.
But you can have page templates for `page-*.php` or your custom `filename.php`:
any-file-name.php
page-*.php
Rename your `single-product.php` file to something else or just remove `single` and rename it something else
Like:
my-single-product.php // this should work
Remember `single-product.php` will be used to render your custom post types (product) single post content.
Edited:
Page templates are only for Wordpress builtin pages. A custom post type is supposed to just have one template. If you have a need to change it then you will most likely want to create another post type or just use pages or the regular posts.
Sources: Page Attributes options for custom post types
Problem
I'm trying to use a custom page template within a custom post type. However the templates option will not display within the post type, when trying to add a new page. Please see the code below: functions.php for the custom post type: ``` add_action( 'init', 'register_cpt_product' ); function register_cpt_product() { $labels = array( 'name' => _x( 'Products', 'product' ), 'singular_name' => _x( 'Product', 'product' ), 'add_new' => _x( 'Add New', 'product' ), 'add_new_item' => _x( 'Add New Product', 'product' ), 'edit_item' => _x( 'Edit Product', 'product' ), 'new_item' => _x( 'New Product', 'product' ), 'view_item' => _x( 'View Product', 'product' ), 'search_items' => _x( 'Search Products', 'product' ), 'not_found' => _x( 'No products found', 'product' ), 'not_found_in_trash' => _x( 'No products found in Trash', 'product' ), 'parent_item_colon' => _x( 'Parent Product:', 'product' ), 'menu_name' => _x( 'Products', 'product' ), ); $args = array( 'labels' => $labels, 'hierarchical' => true, 'description' => 'Product pages', 'supports' => array( 'title', 'editor', 'excerpt', 'thumbnail', 'custom-fields', 'revisions', 'page-attributes' ), 'taxonomies' => array( 'category' ), 'public' => true, 'show_ui' => true, 'show_in_menu' => true, 'menu_position' => 5, 'show_in_nav_menus' => true, 'publicly_queryable' => true, 'exclude_from_search' => false, 'has_archive' => false, 'query_var' => true, 'can_export' => true, 'rewrite' => true, 'capability_type' => 'page' ); register_post_type( 'product', $args ); } ``` page template (except of template tag) ``` <?php /* Template Name: Product */ ?> ```