0

Edit: Now I've found that this is Hybrid Core, and apparently the template hierarchy is different. I still haven't solved my problem below though.

In addition to the title. My thinking is that if I am able to select a template in the backend, it should honor that selection. It doesn't change though. I've tested the other template file in place of the default, and it works.

This is the function to add my custom post type. This works just fine.

add_action( 'init', 'register_cpt_location' );

function register_cpt_location() {

$labels = array(
    'name' => _x( 'Locations', 'info_location' ),
    'singular_name' => _x( 'Location', 'info_location' )
);

$args = array(
    'labels' => $labels,
    'description' => 'Custom Post Type for Location',
    'hierarchical' => true,
    'supports' => array( 'title', 'editor', 'thumbnail', 'custom-fields', 'revisions', 'page-attributes' ),
    'public' => true,
    'show_ui' => true,
    'show_in_menu' => true,
    'menu_position' => 6,
    'show_in_nav_menus' => true,
    'publicly_queryable' => true,
    'exclude_from_search' => true,
    'has_archive' => true,
    'query_var' => true,
    'can_export' => true,
    'rewrite' => array( 
        'slug' => 'location', 
        'with_front' => false,
        'feeds' => true,
        'pages' => true
    ),
    'menu_icon' => 'dashicons-location',
    'capability_type' => 'post'
);

register_post_type( 'info_location', $args );   
}

When I add a template for the custom post type (only to use on a few posts), the metabox shows up with my new template. However, the live page still uses the default template for the custom post type.

The default template is "info_location.php".

This is my head info for the template file "info_location-fm.php".

/*
* Template Name: Location-fm
* Template Post Type: info_location
*/

showing the drop down for templates (below)

showing the drop down for templates

new template selected and saved, still doesn't work (below)

new template selected and saved, still doesn't work

1 Answer 1

0

in your code:

$labels = array(
    'name' => _x( 'Locations', 'info_locaiton' ),
    'singular_name' => _x( 'Location', 'info_location' )
);

use this:

$labels = array(
    'name' => _x( 'Locations', 'info_location' ),
    'singular_name' => _x( 'Location', 'info_location' )
);

In $labels variable name array value has different slug. I think this can be a problem. So, you can correct it and check. Or you can use custom post type plugin to make custom post type easily.

Hope this will help!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.