I have a custom post type called "artists". Attached to this is a custom taxonomy, genre
.
Now, URLs /genre/<post slug>
works perfectly fine, however the naked taxonomy page /genre/
gives a 404 error, and I'm struggling to find the error in my code that would do this.
This is my code:
// Genre
add_action( 'init', '_ct_genre', 0 );
function _ct_genre() {
$label_p = 'Genrer';
$label_s = 'Genre';
register_taxonomy( 'genre', 'artists', array(
'labels' => array(
'name' => $label_p,
'singular_name' => $label_s,
'menu_name' => $label_p,
'all_items' => 'Alla ' . strtolower($label_p),
'parent_item' => 'Förälder',
'parent_item_colon' => 'Förälder:',
'new_item_name' => 'Nytt namn på ' . strtolower($label_s),
'add_new_item' => 'Ny ' . strtolower($label_s),
'edit_item' => 'Redigera ' . strtolower($label_s),
'update_item' => 'Uppdatera ' . strtolower($label_s),
'search_items' => 'Sök ' . strtolower($label_p),
'add_or_remove_items' => 'Lägg till eller Ta bort ' . strtolower($label_p)
),
'hierarchical' => false,
'public' => true,
'show_ui' => true,
'show_admin_column' => true,
'show_in_nav_menus' => true,
'has_archive' => true,
'show_tagcloud' => true,
'update_count_callback' => '_update_post_term_count',
'query_var' => true,
'publicly_queryable' => true,
'rewrite' => array(
'slug' => 'genre',
'with_front' => true,
'hierarchical' => true
)
) );
}
All similar issues on StackExchange that I have found, does not apply here.
- I've tried setting
query_var
to a string 'genre' instead, however that didn't work either. - I have of course flushed permalinks after each and every change.
has_archive
is forregister_post_type()
and notregister_taxonomy()
. Have you tried'has_archive' => 'genre'
withregister_post_type()
? That will give you a custom post type archive accessible atexample.com/genre
. However, the posts being displayed would be from any taxonomies attached to the post type.genre
and assign it to a custom template, and in that template, you can run a custom SQL like this. Or you can trytax_query
with theterms
set to term IDs of terms in thegenre
taxonomy - example.