We did create a custom post type calledservice
and a custom taxonomy calledservice_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!
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Find the answer in similar questions on our website.
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.
PHP (from the English Hypertext Preprocessor - hypertext preprocessor) is a scripting programming language for developing web applications. Supported by most hosting providers, it is one of the most popular tools for creating dynamic websites.
The PHP scripting language has gained wide popularity due to its processing speed, simplicity, cross-platform, functionality and distribution of source codes under its own license.
https://www.php.net/
Welcome to the Q&A site for web developers. Here you can ask a question about the problem you are facing and get answers from other experts. We have created a user-friendly interface so that you can quickly and free of charge ask a question about a web programming problem. We also invite other experts to join our community and help other members who ask questions. In addition, you can use our search for questions with a solution.
Ask about the real problem you are facing. Describe in detail what you are doing and what you want to achieve.
Our goal is to create a strong community in which everyone will support each other. If you find a question and know the answer to it, help others with your knowledge.