I am having problem when I want to display my taxonomy template.
I have created one custom taxonomy 'Location' for my custom post type 'Project'. Moreover, I have created templates for it as :
taxonomy-{taxonomy_name}-{term}.php
taxonomy-{taxonomy_name}.php
taxonomy.php
None of them work... I just get my archive-{post_type}.php in all case.
My targetted URLs are :
mywebsite.com/holliday/united-kingdom/
(Location taxonomy)
mywebsite.com/holliday/united-kingdom/london
(Location taxonomy child)
I should have messed up or missed something when creating my taxonomy but can't get it right.
Here is my code (register post type and register taxonomy) :
// Register Post Type (Holliday)
$capability = 'publish_posts';
$cpt_args = array(
'menu_icon' => 'dashicons-groups',
'labels' => array(
'name' => __( 'Holliday', 'mon-plugin' ),
'singular_name' => __( 'Holliday', 'mon-plugin' ),
'add_new' => __( 'Add Holliday', 'mon-plugin' ),
'add_new_item' => __( 'Add Holliday', 'mon-plugin' ),
'edit' => __( 'Edit', 'mon-plugin' ),
'edit_item' => __( 'Edit Holliday', 'mon-plugin' ),
'new_item' => __( 'New Holliday', 'mon-plugin' ),
'view' => __( 'View Holliday', 'mon-plugin' ),
'view_item' => __( 'View Holliday', 'mon-plugin' ),
'search_items' => __( 'Search Holliday', 'mon-plugin' ),
'not_found' => __( 'No Holliday found', 'mon-plugin' ),
'not_found_in_trash'=> __( 'No Holliday found in Trash', 'mon-plugin' ),
'parent' => __( 'Parent Holliday', 'mon-plugin' ),
),
'public' => true,
'has_archive' => true,
'rewrite' => array(
'slug' => 'holliday/%my_project_location%',
),
'supports' => array('title', 'custom-fields', 'excerpt', 'editor', 'author', 'thumbnail', 'comments'),
'capabilities' => array(
'publish_posts' => $capability,
'edit_posts' => $capability,
'edit_others_posts' => $capability,
'delete_posts' => $capability,
'delete_others_posts'=> $capability,
'read_private_posts'=> $capability,
'edit_post' => $capability,
'delete_post' => $capability,
'read_post' => $capability
),
);
register_post_type( 'my_project', $cpt_args );
// Register Taxonomy (Location)
$cats_args = array(
'labels' => array(
'name' => _x( 'Project Location', 'mon-plugin' ),
'singular_name' => _x( 'Location', 'mon-plugin' ),
'search_items' => __( 'Search Location', 'mon-plugin' ),
'all_items' => __( 'All Location', 'mon-plugin' ),
'parent_item' => __( 'Parent Location', 'mon-plugin' ),
'parent_item_colon' => __( 'Parent Location:', 'mon-plugin' ),
'edit_item' => __( 'Edit Location', 'mon-plugin' ),
'update_item' => __( 'Update Location', 'mon-plugin' ),
'add_new_item' => __( 'Add New Location', 'mon-plugin' ),
'new_item_name' => __( 'New Location Name', 'mon-plugin' ),
'menu_name' => __( 'Location', 'mon-plugin' ),
),
'hierarchical' => true,
'public' => true,
'show_ui' => true,
'has_archive' => true,
'rewrite' => array(
'slug' => 'holliday',
'hierarchical' => true
)
);
register_taxonomy( 'my_project_location', 'my_project', $cats_args );
EDIT:
If I change my taxonomy slug into something else, I get my taxonomy template working.
Example:
taxonomy slug => "location"
mywebsite.com/location/united-kingdom/ => Taxonomy template working !
But I want my taxonomy to work with my custom post type. To get my taxonomy template when accessing mywebsite.com/{custom-post-type}/{taxonomy}/
But this give me archive-{custom-post-type}.php
file instead.
Following the Template Hierarchy I expect Wordpress to find me the taxonomy template before the archive template.
Is there something I am missing ?
Thank you for your help.
unregister_taxonomy
and then re-register it with a totally different URL just to test out whether or not this is the case, then if so, find a new permalink plan.