Home  >  Q&A  >  body text

How to set custom category archive link to /%category%/%taxonomy%

I am developing a WordPress site for the first time in a while and I would like to change the custom taxonomy archive link to /�tegory%/%taxonomy%.

In my use case, the category is TV series and the custom taxonomy represents the seasons. So if the post's category is "Star Trek: The Next Generation" and the custom category is "Season 1", I want /tng/s1 to be in taxonomy-season.php template. However, this URL currently displays the category.php template.

Can anyone help with the correct rewrite rules? Here's everything I know about custom taxonomies:

register_taxonomy(
    'season',
    'post',
    array(
        'public'  => true,
        'labels'  => array(
            'name' => 'season',
        ),
        'rewrite' => array(
            'slug' => '%category%',
        ),
    )
);

P粉463824410P粉463824410251 days ago470

reply all(1)I'll reply

  • P粉327903045

    P粉3279030452024-01-17 20:24:53

    There is no native way in Wordpress to get categories by tags. The reason is that tags have nothing to do with categories, they are independent. That being said, the only way to get all the tags used by a specific category is to loop through every post in that category and get the tags for each post.

    I recommend making subcategories for the parent TV show.

    Then in category.php there is an if else statement (if it is a child post etc.)

    reply
    0
  • Cancelreply