Skip to main content
Add taxonomy slug changed example
Source Link

I have aam having problem withwhen 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 :

Even after trying solutions found on this forumEDIT:
If I change my taxonomy slug into something else, I am still stuckget 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.

I have a problem with my custom taxonomy 'Location' for my custom post type 'Project'. I have created templates for it as :

Even after trying solutions found on this forum, I am still stuck.
Thank you for your help.

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 :

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.

added URLs targetted
Source Link

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.

I should have messed up or missed something when creating my taxonomy but can't get it right.

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.

added 1645 characters in body
Source Link

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'              => 'project''holliday',
        'hierarchical'      => true
    )
);
// Register taxonomy
register_taxonomy( 'project_location''my_project_location', 'project''my_project', $cats_args );

Here is my code :

$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'              => 'project',
        'hierarchical'      => true
    )
);
// Register taxonomy
register_taxonomy( 'project_location', 'project', $cats_args );

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 );
Source Link
Loading