0

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!

  • have you flushed rewrites rules after every change ? – mmm Oct 21 '17 at 14:17
  • Yes, of course) – Orkhan Hasanli Oct 21 '17 at 14:21
  • I juste try your code, I change '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 Oct 21 '17 at 15:06
  • products is the slug you’ve given your taxonomy, a 404 for that url is expected, only individual terms have archives. – Milo Oct 21 '17 at 15:09
  • Earlier I have installed woocommerce and then delete this plugin. May be in Database Woocommerce left some strings? – Orkhan Hasanli Oct 21 '17 at 15:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.