V
V
Vyacheslav Naumenko2019-06-10 13:48:55
WordPress
Vyacheslav Naumenko, 2019-06-10 13:48:55

How to change URL in WordPress?

Registered a new record type "collections".
And the taxonomy "collections-brands" was made to it.
Now the link to all collections looks like this: /collections/
Now the link to all collections of the brand looks like this: /collections-brands/BRAND/
Now the link to a specific collection looks like this: /collections/SPECIFIC_COLLECTION/
And it should be:
All: /collections/
Brand: /BRAND/collections/
Specific: /BRAND/collections/SPECIFIC_COLLECTION/
How to do this?
I have already re-read everything, nowhere is my case, I tried it like this:

add_action('init', function(){
    global $wp_rewrite;

    // добавим тег перезаписи, чтобы add_permastruct() его поняла
    // он потом будет заменен на часть регулярки указанной во втором параметре
    $wp_rewrite->add_rewrite_tag( '%collections%', '([^/]+)', "post_type=collections&name=" );
    $wp_rewrite->add_rewrite_tag( '%collections-brands%', '([^/]+)', "post_type=collections-brands&name=" );

    $permastruct = '%collections-brands%/collections/%collections%'; // наша структура ЧПУ
    // добавляем структуру ЧПУ
    $wp_rewrite->add_permastruct( 'collections', $permastruct, array(
        'with_front'  => true,
        'paged'       => true,
        'feed'        => false,
        'forcomments' => false,
        'walk_dirs'   => false,
        'endpoints'   => false,
    ) );
}, 1);

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vyacheslav Naumenko, 2019-06-10
@VNaumenko

Did it like this:

add_action('init', function(){
    global $wp_rewrite;
    $permastruct = '%collections-brands%/collections'; // наша структура ЧПУ
    // добавляем структуру ЧПУ
    $wp_rewrite->add_permastruct( 'collections-brands', $permastruct, array(
        'with_front'  => true,
        'paged'       => true,
        'feed'        => false,
        'forcomments' => false,
        'walk_dirs'   => false,
        'endpoints'   => false,
    ) );

}, 1);

Now works /BRAND/collections/ BUT 404 error

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question