How to build overlapping custom post_type and taxonomy rewrites without conflicts?

by Stratboy   Last Updated August 03, 2017 14:08 PM

custom post type: gallery

taxonomy: gallery_type (ex terms: photo, video)

wanted urls: > all 'gallery' custom posts > all 'gallery' custom posts belonging to 'video' term > the 'gallery' custom post called 'My Fabulous  Gallery 1'

unwanted urls:

I think this is quite a common problem. In the past I already solved it in various ways with the use of add_rewrite_rule() and some regexp astro-magics. Ok.


  • Since register_post_type/taxonomy do have a rewrite option (which I usually use for simple things), I wonder: are there more elegant and less involved ways to achieve the results I want?

  • Also, after changing the rules/routes/rewrites, I'd like to have wordpress to correctly generate links and things like that, using its standard functions (get_the_permalink() etc...). How to?

There's an old and quite good article out there:

If you take a look to "Manipulating WordPress Rewrites" you'll see they suggest ways to achieve what I want, but they don't work perfectly. I get the first 2 urls, but this one will not work:

it will redirect to the standard one:

Related Questions

Change CPT permalink to use the category

Updated June 11, 2019 20:08 PM