Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have a custom post type, course with an associated custom taxonomy curriculum-area. On the permalink domain.com/course/, a list of all courses is shown as expected. However, on the permalink domain.com/curriculum-area/equality, it shows the home page. (The home page is a static page). I would like it to, instead, show an archive of all courses in the specified curriculum-area: equality. Also, if I have a front-page.php, this archive page also uses the template from front-page.php.

How can I get the archive.php template to be applied to this custom taxonomy?

// functions.php:

<?php

// add thumbnail support
add_theme_support( 'post-thumbnails' ); 

// add custom post type 'Course'
add_action( 'init', 'register_cpt_course' );

function register_cpt_course() {

    // custom taxonomy - curriculum area
    $args_curriculum_area_taxonomy = array(
        'hierarchical'          => true,
        'labels'                => array(
            'name' => 'Curriculum Areas',
            'singular_name' => 'Curriculum Area'
        ),
        'show_ui'               => true,
        'show_admin_column'     => true,
        'update_count_callback' => '_update_post_term_count',
        'query_var'             => true,
        'rewrite'               => true
    );

    register_taxonomy( 'Curriculum Area', 'course', $args_curriculum_area_taxonomy );

    // custom post type - course
    $cpt_course_args = array( 
        'labels' => array(
            'name' => 'Courses',
            'singular_name' => 'course'
        ),
        'hierarchical' => false,
        'description' => 'The place to display courses',
        'supports' => array( 'title', 'editor', 'thumbnail', 'custom-fields', 'revisions' ),
        'taxonomies' => array( 'curriculum_area' ),
        'public' => true,
        'show_ui' => true,
        'show_in_menu' => true,
        'menu_position' => 5,

        'show_in_nav_menus' => true,
        'publicly_queryable' => true,
        'exclude_from_search' => false,
        'has_archive' => true,
        'query_var' => true,
        'can_export' => true,
        'rewrite' => array(
            'slug' => 'course',
            'with_front' => true
        ),
        'capability_type' => 'post'
    );

    register_post_type( 'course', $cpt_course_args );

}

?>
share|improve this question

2 Answers 2

Your permalink as given is domain.com/curriculum-area/equality but you registered your taxonomy as Curriculum Area. So for domain.com/curriculum-area/equality to work, change Curriculum Area in register_taxonomy( 'Curriculum Area', 'course', $args_curriculum_area_taxonomy ); to register_taxonomy( 'curriculum-area', 'course', $args_curriculum_area_taxonomy );. Also change this line 'taxonomies' => array( 'curriculum_area' ), to 'taxonomies' => array( 'curriculum-area' ), I forgot to say, remember to update your permalinks after these changes

share|improve this answer

This is dependent on your template hierarchy and not the code you showed. archive.php is the fallback template for date, taxonomy, tag, author, category and ctp archive pages. So it should be rendering your archive taxonomy page.

Look at the code in your archive.php and see what it is doing, for example, it could be loading a specific loop or including another file which does the loop. You can revert to one of the default themes to narrow down the problem.

It's usually a good idea is to specify a specific template for curriculum-area by creating a page like taxonomy-curriculum-area.php and if you want you can even do taxonomy-equality.php.

See: https://codex.wordpress.org/Template_Hierarchy#Custom_Taxonomies_display

share|improve this answer
    
I have looked at the Template Hierarchy in depth. I only have front-page.php, index.php, archive.php and functions.php in this theme so far. The fact this issue persists with the WP default themes leads me to believe it's code related. –  George Feb 23 at 17:11

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.