• Not sure if I am going mad, but I can’t seem to figure out how to add the template selection with my custom post type.

    With Posts and Pages, I can select a template. Now I want to do the same with my custom post type. Everything works perfectly, but I can’t seem to make this work… Or show.

    This is my registration of the custom post type.

    function create_posttype_courses()
    {
    register_post_type(
    'mycustomtype',
    array(
    'capability_type' => 'page',
    'labels' => array(
    'name' => __('Custom Types'),
    'singular_name' => __('Custom Type')
    ),
    'public' => true,
    'has_archive' => true,
    'rewrite' => array('slug' => 'mycustomtype'),
    'show_in_rest' => true,
    'template' => array(),
    'supports' => array(
    'title',
    'editor',
    'excerpt',
    'author',
    'thumbnail',
    'comments',
    'revisions',
    'page-attributes'
    ),
    'hierarchical' => true,
    )
    );
    }
    add_action('init', 'create_posttype_courses');

    Most answers I found was that you have to add the ‘page-attributes’ to the supports array, but that makes no difference.
    The ‘show_in_rest’ seems to be important too, not sure why. But it has been set to true from the start.

    Does anyone know what I am doing wrong?

    Thanks!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Hi @banana828
    Thanks for reaching out us on the www.remarpro.com support forum. We would be happy to assist with any issues you are facing.

    Your code looks correct overall, to solve this issue you may try by adding the following comment at the top of your custom page template file.

    Template Post Type: post, page, mycustomtype

    With this addition, your custom page template should now look like this:

    <?php
    /*
    Template Name: Name of the template
    Template Post Type: post, page, mycustomtype
    */

    // Page code here…

    Don’t forget to resave the permalink structure by going Settings > Permalinks in the WordPress dashboard.

    Let us know if this resolves the issue.

    Regards,
    Mashiur R.

    Thread Starter banana828

    (@banana828)

    @mashiurz thanks for replying. I did forget to mention I added that to the template. This is my template page (named mycustomtype-single.php):

    <?php
    /*
    Template Name: My Custom Type Template Single
    Template Post Type: mycustomtype
    */

    echo "Hello world!";
    ?>

    But the dropdown is still not showing:

    (redacted for personal stuff)

    There are other templates, because when I edit a page (not the custom post type) I see that dropdown.

    Moderator bcworkz

    (@bcworkz)

    A “Template Post Type” comment header value works on my near plain vanilla test site. Plain except for the addition of a custom post type and template anyway. Apparently your theme or one of your plugins is interfering. Or you’re using a block theme. .php templates are not valid for block themes.

Viewing 3 replies - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.