Custom Post Type Archive Template

I think you should add support for custom taxonomy types and name the file taxonomy-cpt-type.php where cpt is the name of your Custom Post Type.

Your CPT archive file should be named archive-cpt.php where cpt is the name of your Custom Post Type.

Here’s all the code which has been tested.

Note: You shouldn’t be using tag or tags as the name of your custom taxonomy type as it will conflict with existing core functions.

add_action( 'init', 'wpsites_cpt_post_type' );
function wpsites_cpt_post_type() {

register_post_type( 'cpt',
    array(
        'labels' => array(
            'name'          => __( 'CPT', 'theme' ),
            'singular_name' => __( 'CPT', 'theme' ),
        ),
        'has_archive'  => true,
        'hierarchical' => true,
        'menu_icon'    => true,
        'public'       => true,
        'rewrite'      => array( 'slug' => 'cpt', 'with_front' => false ),
        'supports'     => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'trackbacks', 'custom-fields', 'revisions', 'page-attributes' ),
        'taxonomies'   => array( 'cpt-type' ),

    ));

}

And this for registering a Taxonomy Type page where you can create unlimited tax types.

add_action( 'init', 'wpsites_register_taxonomy_types' );
function wpsites_register_taxonomy_types() {

register_taxonomy( 'cpt-type', 'cpt',
    array(
        'labels' => array(
            'name'          => _x( 'Types', 'taxonomy general name', 'theme' ),
            'add_new_item'  => __( 'Add New CPT Type', 'theme' ),
            'new_item_name' => __( 'New CPT Type', 'theme' ),
        ),
        'exclude_from_search' => true,
        'has_archive'         => true,
        'hierarchical'        => true,
        'rewrite'             => array( 'slug' => 'cpt-type', 'with_front' => false ),
        'show_ui'             => true,
        'show_tagcloud'       => false,
    ));

}

Replace all instances of cpt with the name of your custom post type then re-save your Permalink settings.

Otherwise, it may be a problem with the code in your taxonomy-cpt-type.php file.

Leave a Comment