0
votes

I have created custom post type for my project and I want to add custom post type with page attribute. I have done this with following code:

function register_pt_boutique()
{
    register_post_type('boutique', array(
        'label'           => 'Boutiques',
        'description'     => 'This post type represents the featured items on the homepage.',
        'public'          => true,
        'show_ui'         => true,
        'show_in_menu'    => true,
        'capability_type' => 'post',
        'map_meta_cap'    => true,
        'hierarchical'    => true,
        // 'rewrite' => array('slug' => 'featured', 'hierarchical' => true, 'with_front' => false),
        'query_var'       => true,
        'has_archive'     => true,
        'menu_position'   => '7',
        'supports'        => array('title', 'page-attributes','thumbnail'),
        // 'taxonomies' => array('page-attributes'),
        'labels'          => array(
            'name'               => 'Boutiques',
            'singular_name'      => 'Boutique',
            'menu_name'          => 'Boutiques',
            'add_new'            => 'Add Boutique',
            'add_new_item'       => 'Add New Boutique',
            'edit'               => 'Edit',
            'edit_item'          => 'Edit Boutique',
            'new_item'           => 'New Boutique',
            'view'               => 'View Boutique',
            'view_item'          => 'View Boutique',
            'search_items'       => 'Search Boutique',
            'not_found'          => 'No Boutique',
            'not_found_in_trash' => 'No Boutique Found in Trash',
            'parent'             => 'Parent Boutique',
        )
    ));
}

Using this code page attribute option come with two fields ("parent" and "order") at admin side but without "template" field option. I want page attribute with "template" field.

2
You dont need to specify the templates in the register_post_type function. Instead, just create your post-templates like you would do with your normal page-templates. See wordpress.stackexchange.com/questions/254772/… - Meetai.com

2 Answers

1
votes

Just as you gave the template name in the page template file:

Template Name: <template name>

You can specify the custom post types as Template Post Type where you want to show:

Template Post Type: <custom_post_type_1>, <custom_post_type_2>, <custom_post_type_3>

for example: I want to add page attribute to the portfolio one of my custom post type:

In my page template, I have added:

Template Name: Portfolio Design
Template Post Type: portfolio

Also, don't forget to add 'page-attributes' to 'supports' array during cpt registration:

'supports' => array(
            'custom-fields',
            'page-attributes'
        ), 

If you want to change label 'Page Attributes' then assign to 'attributes' in 'labels' array i.e :

'labels' => array(
    'name' => 'Portfolios',
    'singular_name' => 'Portfolio',
    'attributes' => 'Page Attributes'
),

A screenshot of the dashboard for custom post type editor is: page attribute for custom post type = portfolio

-2
votes

from wordpress 4.7 you can include the field "template" directly from de file https://make.wordpress.org/core/2016/11/03/post-type-templates-in-4-7/