Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WordPress Custom Post Type Choose Template Dropdown Missing

I am new at WordPress, I created a Custom Post Type, but even after adding "page-attributes" I do not see the template dropdown for choosing my custom template only "Order" field is visible.

My theme has 3 different menus(top, main and footer) where all these menus have same templates for each menu, for example: the main menu has central, east, west, north and south location, have the same layout, same for Top menu as well.

Each location in the main menu and Top menu is an archive page, where I can show the listing of that location posts for further viewing. But by following the conventional archive-{post_type}.php I have to create a new archive page for each location.

Here is the code for main menu:

[
    "capability_type" => "post",
    "description" => "Holds our location's specific data",
    "public" => true,
    "menu_position" => 5,
    "has_archive" => true,
    "show_admin_column" => true,
    "supports" => [
        "title",
        "editor",
        "thumbnail",
        "excerpt",
        "revisions",
        "page-attributes"
    ],
    "taxonomies" => [
        "post_tag"
    ],
    "labels" => [
        "name" => "Locations",
        "singular_name" => "Location",
        "add_new" => "Add Location",
        "add_new_item" => "Add Location" ,
        "edit_item" => "Edit Location",
        "new_item" => "New Location",
        "all_items" => "Locations" ,
        "view_item" => "View Location",
        "search_items" => "Search Location",
        "not_found" => "No Locations found",
        "not_found_in_trash" => "No Locations found in the Trash",
        "parent_item_colon" => "",
        "menu_name" => "Locations"
    ]
]

Here is the output:

enter image description here

Please help in fixing this issue.

Thanks

like image 811
MrSingh Avatar asked Aug 20 '26 20:08

MrSingh


1 Answers

Previously this was only available to pages. But as of 4.7 it's available for all post types, you just need to add Template Post Type to the file header.

eg.

<?php
/*
Template Name: Full-width layout
Template Post Type: post, page, product
*/

// … your code here

https://make.wordpress.org/core/2016/11/03/post-type-templates-in-4-7/

like image 162
ngearing Avatar answered Aug 22 '26 22:08

ngearing



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!