1

I have a little problem with showing of my taxonomy template my codes to create custom post type are:

    function setup_projects_cpt(){
    $labels = array(
        'name' => esc_html_x('Projects','teklan'),
        'singular_name' => esc_html_x('Project', 'post type singular name' , 'teklan'),
        'add_new' => esc_html_x('Add New', 'Project','teklan'),
        'add_new_item' => esc_html__('Add New Project'),
        'edit_item' => esc_html__('Edit Project'),
        'new_item' => esc_html__('New Project'),
        'all_items' => esc_html__('All Projects'),
        'view_item' => esc_html__('View Project'),
        'search_items' => esc_html__('Search Projects'),
        'not_found' => esc_html__('No Projects Found'),
        'not_found_in_trash' => esc_html__('No Projects found in the trash'),
        'parent_item_colon' => '',
        'menu_name' => 'Projects'
    );
    $args = array(
        'labels' => $labels,
        'description' => 'My Projects',
        'publicly_queryable'=>true,
        'rewrite' => array('slug' => 'projects'),
        'public' => true,
        'menu_position' => 5,
        'supports' => array('title', 'editor', 'thumbnail', 'excerpt', 'custom-fields'),
        'has_archive' => true,
        'taxonomies' => array(''),
        'menu_icon' => 'dashicons-admin-multisite',  https://developer.wordpress.org/resource/dashicons/
    );
    register_post_type('projects', $args);
}
add_action('init', 'setup_projects_cpt');


function projects_taxonomy() {
    register_taxonomy(
        'project_categories', 
        'projects',       
        array(
            'hierarchical' => true,
            'label' => 'Project Categories',  
            'query_var' => true,
            'rewrite' => array(
                'slug' => 'projects', 
                'with_front' => false 
            )
        )
    );
}
add_action( 'init', 'projects_taxonomy');

i've created projects a,b ,c , ... and placed them in category cat1 , cat2 , ... files for template are(in theme folder):

single-projects.php archive-projects.php

when i click on category term in dashboard admin i'd get 404 error .

site.com/projects --> is okay and shows all my projects as i want site.cem/project/a --> is okay and shows single projects content site.com/projects/cat1 --> 404 error !!! how can i solve these problem?

2
  • 2
    You can't use the same rewrite slug for a taxonomy and a post type. When you're visiting site.com/projects/cat1 WordPress is looking for a project post named cat1 because you told it that /projects was for project posts. You need to give the categories a different slug, like project-category or projects/category. Feb 7, 2022 at 13:36
  • @JacobPeattie thanks , what file i should create to use its template instead of index.php
    – wizard2000
    Feb 7, 2022 at 19:16

0

Your Answer

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