I have created taxonomy & custom post type. Here is the code:
add_action('init', 'register_post_types');
function register_post_types(){
register_taxonomy('products', array('product'), array(
'label' => 'Категории продукции',
'labels' => array(
'name' => 'Категории продукции',
'singular_name' => 'Категории продукции',
'search_items' => 'Поиск категорий',
'all_items' => 'Все категории',
'parent_item' => 'Родит. категория',
'parent_item_colon' => 'Родит. категория:',
'edit_item' => 'Редактировать категорию',
'update_item' => 'Обновить категорию',
'add_new_item' => 'Добавить категорию',
'new_item_name' => 'Заголовок',
'menu_name' => 'Категории продукции',
),
'description' => 'Категории продукции',
'public' => true,
'show_in_nav_menus' => false,
'show_ui' => true,
'show_tagcloud' => false,
'hierarchical' => true,
'query_var' => true,
'rewrite' => array('slug' => 'products', 'with_front' => true),
'show_admin_column' => true,
) );
register_post_type('product', array(
'label' => 'Продукция',
'labels' => array(
'name' => 'Продукция',
'singular_name' => 'Продукция',
'add_new' => 'Добавить новую',
'add_new_item' => 'Введите заголовок',
'edit_item' => 'Редактирование продукции',
'new_item' => 'Новая продукция',
'view_item' => 'Посмотреть продукцию',
'search_items' => 'Поиск продукции',
'not_found' => 'Продукций не найдено',
'not_found_in_trash' => 'В корзине продукций не найдено',
'parent_item_colon' => '',
'menu_name' => 'Продукция',
),
'description' => 'Наша продукция',
'public' => true,
'publicly_queryable' => true,
'exclude_from_search' => false,
'show_ui' => true,
'show_in_menu' => true,
'show_in_admin_bar' => true,
'menu_position' => 23,
'menu_icon' => 'dashicons-list-view',
'capability_type' => 'post',
'map_meta_cap' => true,
'hierarchical' => false,
'supports' => array('title', 'thumbnail'),
'taxonomies' => array('products'),
'has_archive' => true,
'rewrite' => array('slug' => 'product', 'with_front' => false),
'query_var' => true,
) );
}
Then I have copied my archive.php, renamed it to taxonomy-products.php and update the Permalinks.
But when I try to open /products the page shows 404 Error. I have also disabled WP No category base plugin and the same error.
I have just tried other answers from other posts:
I solved this issue by making sure that the calls to register my taxonomies were placed before the calls to registering my custom post types. Weird but it works!
'rewrite' => array(
'slug' => 'brands',
'with_front' => true
)
Also checked this:
If you set 'rewrite' => false, then it should not give you any more problems
How I can fix this? Thanks in advance!
I have created taxonomy & custom post type. Here is the code:
add_action('init', 'register_post_types');
function register_post_types(){
register_taxonomy('products', array('product'), array(
'label' => 'Категории продукции',
'labels' => array(
'name' => 'Категории продукции',
'singular_name' => 'Категории продукции',
'search_items' => 'Поиск категорий',
'all_items' => 'Все категории',
'parent_item' => 'Родит. категория',
'parent_item_colon' => 'Родит. категория:',
'edit_item' => 'Редактировать категорию',
'update_item' => 'Обновить категорию',
'add_new_item' => 'Добавить категорию',
'new_item_name' => 'Заголовок',
'menu_name' => 'Категории продукции',
),
'description' => 'Категории продукции',
'public' => true,
'show_in_nav_menus' => false,
'show_ui' => true,
'show_tagcloud' => false,
'hierarchical' => true,
'query_var' => true,
'rewrite' => array('slug' => 'products', 'with_front' => true),
'show_admin_column' => true,
) );
register_post_type('product', array(
'label' => 'Продукция',
'labels' => array(
'name' => 'Продукция',
'singular_name' => 'Продукция',
'add_new' => 'Добавить новую',
'add_new_item' => 'Введите заголовок',
'edit_item' => 'Редактирование продукции',
'new_item' => 'Новая продукция',
'view_item' => 'Посмотреть продукцию',
'search_items' => 'Поиск продукции',
'not_found' => 'Продукций не найдено',
'not_found_in_trash' => 'В корзине продукций не найдено',
'parent_item_colon' => '',
'menu_name' => 'Продукция',
),
'description' => 'Наша продукция',
'public' => true,
'publicly_queryable' => true,
'exclude_from_search' => false,
'show_ui' => true,
'show_in_menu' => true,
'show_in_admin_bar' => true,
'menu_position' => 23,
'menu_icon' => 'dashicons-list-view',
'capability_type' => 'post',
'map_meta_cap' => true,
'hierarchical' => false,
'supports' => array('title', 'thumbnail'),
'taxonomies' => array('products'),
'has_archive' => true,
'rewrite' => array('slug' => 'product', 'with_front' => false),
'query_var' => true,
) );
}
Then I have copied my archive.php, renamed it to taxonomy-products.php and update the Permalinks.
But when I try to open /products the page shows 404 Error. I have also disabled WP No category base plugin and the same error.
I have just tried other answers from other posts:
I solved this issue by making sure that the calls to register my taxonomies were placed before the calls to registering my custom post types. Weird but it works!
'rewrite' => array(
'slug' => 'brands',
'with_front' => true
)
Also checked this:
If you set 'rewrite' => false, then it should not give you any more problems
How I can fix this? Thanks in advance!
Share Improve this question asked Oct 21, 2017 at 13:42 Orkhan HasanliOrkhan Hasanli 1179 bronze badges 7 | Show 2 more comments1 Answer
Reset to default 1My custom taxonomy is "topic" - I needed a page to display all the topics at /topic but it gives a 404.
So I created a normal page in the Wordpress admin with the slug /topic. Then I select the template for the page manually:
function add_custom_templates( $original_template ) {
global wp;
if( isset( $wp ) ) {
if( $wp->request == 'topic' ) {
return trailingslashit( get_template_directory() ) . 'page-topic.php';
}} add_action( 'template_include', 'add_custom_templates' );
Excuse the formatting - this editor is nasty!
'with_front' => TRUE
and public page works with this change. Can you have a conflict with another post type called "product" ? woocommerce e.g. – mmm Commented Oct 21, 2017 at 15:06products
is the slug you’ve given your taxonomy, a 404 for that url is expected, only individual terms have archives. – Milo Commented Oct 21, 2017 at 15:09