So, I’ve been going crazy trying to figure this out. Essentially, I’ve created two custom post types, 'the_case_study
‘ and 'the_video'
, with respective slugs 'case-studies'
and 'videos'
.
I’ve also created three taxonomies which apply to both the_case_study and the_video. These are 'the_room'
, 'the_system'
and 'the_style'
.
By default, the taxonomy archive displays all posts tagged with a given term, and the permalink looks like this:
example.com/room/kitchen (displays all posts tagged with kitchen)
I would like to have a taxonomy archive that will only display the posts of the current custom post type and will have a permalink that is relative to that custom post type. For example:
example.com/case-studies/room/kitchen (should display all case studies tagged with kitchen)
example.com/videos/room/kitchen (should display all videos tagged with kitchen)
I’ve already resolved a similar problem elsewhere on the site, based on this answer among other things. However, I only know how to make that work for one post type.
This seems like something that should be possible, but I don’t know how to go about it. Essentially, I’d like to be able to find the parent of the current taxonomy page, where that parent is the current custom post type… but I’m not sure how that jives with the custom post type and taxonomy constraints.
Is what I’m trying to do possible? Should I be thinking about it differently?
This is very easy to do by adding custom rewrite rules. This should get you started:
As always when changing rewrite rules, be sure to flush your rewrite rules by going to Settings -> Permalinks and click “Save Changes”.
You could alter the query directly in your template or use the pre_get_posts action.
Inside archive template:
Action Hook Method: