php - WordPress - 404 for archive page of custom taxonomy
one text
We did create a custom post type called service
and a custom taxonomy called service_category
.
So we are trying to create the following structure;
Archive page of custom taxonomy = archive-service_category.php
with url /onze-producten-en-diensten
Taxonomy page of custom taxonomy = taxonomy-service_category.php
with url /onze-producten-en-diensten/{taxonomy_name}
Single page of custom post type = single-service.php
with url /onze-producten-en-diensten/{taxonomy_name}/{single_post_name}
The taxonomy and single page are working, but the archive page of the custom taxonomy returns a 404 error.
This is the code we are using;
/**
* Service custom post type
*/
add_action('init', function() {
register_post_type('service', [
'label' => __('Diensten', 'txtdomain'),
'public' => true,
'menu_position' => 5,
'menu_icon' => 'dashicons-book',
'supports' => ['title', 'editor', 'thumbnail', 'author', 'revisions', 'comments'],
'show_in_rest' => true,
'rewrite' => ['slug' => 'dienst'],
'taxonomies' => ['service_category'],
'rewrite' => array('slug' => 'onze-producten-en-diensten/%service_category%', 'with_front' => false),
'labels' => [
'singular_name' => __('Dienst', 'txtdomain'),
'add_new_item' => __('Nieuwe dienst toevoegen', 'txtdomain'),
'new_item' => __('Nieuwe dienst', 'txtdomain'),
'view_item' => __('Dienst bekijken', 'txtdomain'),
'not_found' => __('Geen dienst gevonden', 'txtdomain'),
'not_found_in_trash' => __('Geen dienst gevonden in de prullenbak', 'txtdomain'),
'all_items' => __('Alle diensten', 'txtdomain'),
'insert_into_item' => __('Dienst toevoegen', 'txtdomain')
],
]);
});
/**
* Service taxonomy
*/
add_action('init', function() {
register_taxonomy('service_category', ['service'], [
'label' => __('Dienst categorieen', 'txtdomain'),
'hierarchical' => true,
'has_archive' => true,
'rewrite' => array('slug' => 'onze-producten-en-diensten'),
'show_admin_column' => true,
'show_in_rest' => true,
'labels' => [
'singular_name' => __('Dienst categorieen', 'txtdomain'),
'all_items' => __('Alle dienst categorieen', 'txtdomain'),
'edit_item' => __('Dienst categorie bewerken', 'txtdomain'),
'view_item' => __('Dienst categorie bekijken', 'txtdomain'),
'update_item' => __('Dienst categorie bijwerken', 'txtdomain'),
'add_new_item' => __('Nieuwe dienst categorie toevoegen', 'txtdomain'),
'new_item_name' => __('Nieuwe dienst categorie', 'txtdomain'),
'search_items' => __('Dienst categorie zoeken', 'txtdomain'),
'popular_items' => __('Populaire dienst categorieen', 'txtdomain'),
'not_found' => __('Geen dienst categorie gevonden', 'txtdomain'),
]
]);
});
register_taxonomy_for_object_type('service_category', 'service');
We did try refreshing permalinks, but still no success.
Does someone know why the archive page of the custom taxonomy returns a 404?
Thanks for your time!
Source