admin管理员组

文章数量:1193775

Here is what I am looking for:

Custom Post Type: partner
Archive: domain/partners/ (list all partners)
Custom Taxonomy: country
Archive: domain/partners/denmark/ (list all partners in a country)
Custom Taxonomy: city
Archive: domain/partners/denmark/copenhagen/ (list all partners in a country and in city)
Single: domain/partners/denmark/copenhagen/the-name-of-the-partner-post/

On the custom post type rewrite I have the following:

$rewrite = array(
    'slug'                  => 'partners/%country%',
    'with_front'            => false,
)

It works fin with the following:

domain/partners/denmark/
domain/partners/denmark/copenhagen/
domain/partners/denmark/copenhagen/the-name-of-the-partner-post/

BUT I cannot find a rewrite solution that works with:

domain/partners/

Here is what I am looking for:

Custom Post Type: partner
Archive: domain.com/partners/ (list all partners)
Custom Taxonomy: country
Archive: domain.com/partners/denmark/ (list all partners in a country)
Custom Taxonomy: city
Archive: domain.com/partners/denmark/copenhagen/ (list all partners in a country and in city)
Single: domain.com/partners/denmark/copenhagen/the-name-of-the-partner-post/

On the custom post type rewrite I have the following:

$rewrite = array(
    'slug'                  => 'partners/%country%',
    'with_front'            => false,
)

It works fin with the following:

domain.com/partners/denmark/
domain.com/partners/denmark/copenhagen/
domain.com/partners/denmark/copenhagen/the-name-of-the-partner-post/

BUT I cannot find a rewrite solution that works with:

domain.com/partners/
Share Improve this question asked Sep 6, 2022 at 10:19 Vayu RobinsVayu Robins 12 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

There are probably a few ways to handle this, but I'm guessing the fact that you're using "/partners" in your taxonomy rewrites is messing things up for using "/partners" alone for the CPT.

I think I would probably use "/partners" for the CPT only, and then define a custom rewrite rule that determines what the parameters after the various slashes correspond to.

If you take a look at the examples on the reference page, you might get an idea of what I mean. Specifically, look at the one from Akira Tachibana on that page.

本文标签: Url rewrite with custom post type and taxonomy