C
C
caof192020-08-04 13:10:42
WordPress
caof19, 2020-08-04 13:10:42

How to make term and directory in one url?

Hello, I have a problem with vp. There is a site with products (not woocomerce), they have categories, and they should be (and available) at the url mysite.ru/producia . It displays a list of product categories. Going to the category of products, which is available at mysite.ru/producia/name_cat , all products from this category are displayed. When going to a product, it must have the URL mysite.ru/producia/name_of_product . So the problem is the following, now post_type for products is written like this:

register_post_type('products', array(
    'labels' => array(
      'name'               => __('Продукция', 'carnon'),
    ),
    'public' => true,
    'capability_type' => 'page',
    'hierarchical' => true,
    'menu_icon' => 'dashicons-book',
    'menu_position' => 5,
    'rewrite' => array( 'slug' => 'producia', 'with_front' => false ),
    'supports' => array( 'title', 'editor', 'thumbnail', 'excerpt' ),
    'show_in_rest' => true,
  ));

And for the taxonomy "categories" like this:
register_taxonomy( 'category', [ 'products' ], [ 
    'label'                 => 'Категории', 
    'labels'                => [
      'name'              => 'Категории',
    ],
    'description'           => '', 
    'public'                => true,
    'hierarchical'          => true,
    'capabilities'          => array(),
    'meta_box_cb'           => null, 
    'show_admin_column'     => false, 
    'show_in_rest'          => true,
    'rest_base'             => null,
'rewrite' => array( 'slug' => 'producia', 'with_front' => false ),
  ] );

The problem is this: if you leave everything as it is, then the list of categories and the list of products of the category are available at the desired URL, but the product returns 404 (the page of the permanent link was updated). If "rewrite" is removed from the taxonomy declaration, then the list of categories and the product are available at the desired URL, but then the page with the list of products from the category is available at mysite.ru/category/name_cat (it is generally logical). The question is, is it possible to implement my idea somehow?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question