I have a custom taxonomy, artist, that is related to three custom post types: videos, posts and letters. I have an taxonomy-artist.php
template that should display the archive for a given artist.
When I visit /artist/ARTIST_NAME
it will display the taxonomy archive template only if there are no other posts associated with it. If there are posts associated with it, you get redirected to an individual post (I believe it’s the oldest post associated with the taxonomy term). So if I visit /artist/ARTIST_NAME
and there is content associated with it, I get kicked out to [videos|letters|posts]/THE_POST_NAME
.
I saw something about needing to have taxonomies registered before custom post types, so I am registering the taxonomy first and I’ve flushed out my permalink settings, but no luck. I’m stumped as to why this would be happening, so I would appreciate any ideas about what would cause this!
Here’s the code I’m using for registering the taxonomy and post types:
register_taxonomy( 'artist',
array(
'videos',
'letters',
'post'
),
array(
'labels' => array(
'name' => _x( 'Artists', 'taxonomy general name' ),
'singular_name' => _x( 'Artist', 'taxonomy singular name' ),
'search_items' => __( 'Search Artists' ),
'all_items' => __( 'All Artists' ),
'parent_item' => __( 'Parent Artist' ),
'parent_item_colon' => __( 'Parent Artist:' ),
'edit_item' => __( 'Edit Artist' ),
'update_item' => __( 'Update Artist' ),
'add_new_item' => __( 'Add New Artist' ),
'new_item_name' => __( 'New Artist Name' ),
'menu_name' => __( 'Artists' ),
)
)
);
register_post_type( 'letters',
array(
'labels' => array(
'name' => __( 'Letters' ),
'singular_name' => __( 'Letter' )
),
'public' => true,
'has_archive' => true,
'supports' => array( 'title', 'editor', 'thumbnail' ),
'menu_icon' => get_stylesheet_directory_uri() . '/img/mail.png',
)
);
register_post_type( 'videos',
array(
'labels' => array(
'name' => __( 'Videos' ),
'singular_name' => __( 'Video' )
),
'supports' => array( 'title', 'editor', 'thumbnail' ),
'public' => true,
'menu_icon' => get_stylesheet_directory_uri() . '/img/blue-document-film.png',
)
);
Taxonomy archive index pages for custom taxonomies are not rendered using
archive-{taxonomy}.php
, but rather, usingtaxonomy-{taxonomy}-{term}.php
, which falls back totaxonomy-{taxonomy}.php
, which falls back totaxonomy.php
. Refer to the Template Hierarchy.WordPress interprets
archive-{foobar}.php
asarchive-{post-type}.php
, and would use that template to render the archive index for thefoobar
post-type. So, yourartist
taxonomy archive index page will never be rendered usingarchive-artist.php
.Try renaming the template file to
taxonomy-artist.php
.Finally figured this out. It turns out the original author of the theme was overriding this. My setup was correct, I just had to remove the overrides.