• I built a CPT called case studies. Everything seems to be working correctly except when I try and visit the taxonomy category pages. When I try and visit them, I get a 404 error.

    for example: https://www.mydomain.com/case-studies/categories/hospitality/

    Here is my code used to register both the CPT and Taxonomy.

    /*****************************************
     * Add custom post type for Case Study *
     *****************************************/
    
    add_action('init', 'case_study_register');
    
    function case_study_register() {
    
        $labels = array(
            'name' => 'Case Studies',
            'singular_name' => 'Case Study',
            'add_new' => 'Add New',
            'add_new_item' => 'Add New Case Study',
            'edit_item' => 'Edit Case Study',
            'new_item' => 'New Case Study',
            'view_item' => 'View Case Study',
            'search_items' => 'Search Case Study',
            'not_found' =>  'Nothing found',
            'not_found_in_trash' => 'Nothing found in Trash',
            'parent_item_colon' => ''
        );
    
        $args = array(
            'labels' => $labels,
            'public' => true,
            'publicly_queryable' => true,
            'show_ui' => true,
            'query_var' => true,
            'has_archive' => true,
            'rewrite' => array( 'slug' => 'case-studies', 'with_front' => false ),
            'capability_type' => 'post',
            'menu_position' => 6,
            'supports' => array('title', 'excerpt', 'editor','thumbnail') //here you can specify what type of inputs will be accessible in the admin area
          );
    
        register_post_type( 'casestudy' , $args );
    }
    
    /****************************************
     * Add custom taxonomy for Case Study *
     ****************************************/
    
    add_action('init', 'case_study_categories_register');
    
    function case_study_categories_register() {
    $labels = array(
        'name'                          => 'Case Study Categories',
        'singular_name'                 => 'Case Study Category',
        'search_items'                  => 'Search Case Study Categories',
        'popular_items'                 => 'Popular Case Studes Categories',
        'all_items'                     => 'All Case Study Categories',
        'parent_item'                   => 'Parent Case Study Category',
        'edit_item'                     => 'Edit Case Study Category',
        'update_item'                   => 'Update Case Study Category',
        'add_new_item'                  => 'Add New Case Study Category',
        'new_item_name'                 => 'New Case Study Category',
        'separate_items_with_commas'    => 'Separate Case Study categories with commas',
        'add_or_remove_items'           => 'Add or remove Case Study categories',
        'choose_from_most_used'         => 'Choose from most used Case Study categories'
        );
    
    $args = array(
        'label'                         => 'Case Study Categories',
        'labels'                        => $labels,
        'public'                        => true,
        'hierarchical'                  => true,
        'show_ui'                       => true,
        'args'                          => array( 'orderby' => 'term_order' ),
        'rewrite'                       => array( 'slug' => 'case-studies/categories', 'with_front' => false ),
        'query_var'                     => true
    );
    
    register_taxonomy( 'case_study_categories', 'casestudy', $args );
    }

    Thank you in advance for your help!

Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    Did you visit the permalinks settings screen after adding your code? Either that or execute flush_rewrite_rules() (once only, don’t do this on every page request).

    If you did that and still have trouble, use the query monitor plugin to examine the actual SQL used. Something about it is causing nothing to be returned, hence the 404. What that something is should be a good clue towards the root cause.

Viewing 1 replies (of 1 total)
  • The topic ‘CPT Taxonomy category pages give 404’ is closed to new replies.