Archive page of taxonomy returns a 404 error

I'm trying to create a template file for a custom taxonomy archive page but I keep getting a 404 error when trying to access that archive page.

Basically something like: domain.com/quizzes/quiz-levels/

I managed to create template files for /quizzes/ and /b1-intermediate/ (or whatever the level is), but when I land on domain.com/quizzes/quiz-levels/ I get a 404 error doesn't take any template file.

What I'm aiming for is the following:

  • domain.com/quizzes/ : To show all the quizzes (Works)
  • domain.com/quiz-post-slug/ : To show the quiz post (Works)
  • domain.com/quiz-levels/a1-beginner/ : To show quizzes belonging to this level (works)
  • domain.com/quiz-levels Or domain.com/quizzes/quiz-levels/ : To show the available levels (Doesn't work).
function quiz_custom_post_type() {
  $args = array(
          'labels'                = array(
                                            'name' = 'Quizzes',
                                            'singular_name' = 'Quiz'
                                  ),
          'public'                = true,
          'has_archive'           = true,
          'menu_icon'             = 'dashicons-editor-spellcheck',
          'menu_position'         = 4,
          'has_archive'           = true,
          'supports'              = array('title', 'editor', 'thumbnail', 'custom-fields', 'comments'),
          'show_in_rest'          = true,
          'rest_base'             = 'quizzes',
          'rest_controller_class' = 'WP_REST_Posts_Controller'
          
  );
  register_post_type('quizzes', $args);
}
add_action('init', 'quiz_custom_post_type');


function quiz_levels_taxonomy() {

  $args = array(
                'labels' = array(
                                  'name'          = 'Levels',
                                  'singular_name' = 'Level',
                                  'add_new_item'  = 'Add New Level'
                ),
                'public' = true,
                'hierarchical' = true,
                'show_in_rest' = true,
                'show_admin_column' = true,
                'rewrite' = array('slug'='quiz-levels')
  );
  register_taxonomy('levels', array('quizzes'), $args);
}
add_action('init', 'quiz_levels_taxonomy');

Thanks in advance!

Topic template-hierarchy custom-taxonomy custom-post-types Wordpress

Category Web

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.