I have registered a new post type and made a custom template to display it. According to WP´s latest support for CPT templates, all it takes to make it available for any given CPT is to place this header on the template file:
/** * Template Name: Single Book * Template Post Type: book */
Then, following the template hierarchy, I named my template
single-book.php. And alright, now I have this template available for the 'book' post type. It works. Cool!
However, for some reason, I still need to manually select it within the post attribute section every time I create a new book as the default selection is the standard template for posts. (when the default should be my custom template after naming it as stated above, right? Unless I´m missing something...)
So, the way it is, if by any chance I / the user forgets to change it, the CPT will obviously NOT display properly on the front-end as it isn´t using the template made for it.
I must prevent that from happening and, as I´ll be working with plenty CPTs, I need the ability to choose from 2 approaches when registering a CPT:
1- Determining which template is selected by default on the post attribute section. (ideal for CPTs that can use a range of custom templates depending on the circumstance, but making sure the default selection is appropriate and NOT any other standard template);
2- Making the post attribute section DISAPPEAR for CPTs that should ONLY use a specific custom template. (while making sure that´s the one being used).
I´ve done extensive research and couldn´t find anything at all on how to go about this.
Yet, I suspect this not only can be easily achieved without much hassle but also that it has to do with some parameter within the post type array when registering it.
I´m not sure, but maybe something along the lines of:
add_theme_support('custom-post', array ( 'book'=> array ( 'singular' => ... , 'plural' => ... , 'supports' => array(...), 'some-parameter-to-set-default-template' => ... , 'some-parameter-to-disable-post-attribute-selection' => ... ), ) );
Can anyone help?