I have a big problem. I have been banging my head on this all day long. It seems to be a stupid easy question. Possibly also with a stupid easy answer. But I can’t seem to find it.
What I want is simple. I have a custom_post_type called “producten” and a taxonomy called “producten_categorie”. Inside there I have got some couple hundred products that are all assigned to a “produten_categorie” term. I want to change the permalinks so they display the taxonomy term in the product permalink.
What I have now is as follows:
- www.domain.com/producten/ (producten archive)
- www.domain.com/producten/category (producten category archive)
- www.domain.com/producten/category/subcategory (producten subcategory archive)
- www.domain.com/producten/post_tile (single page for post in “producten”)
What I want is the following:
- www.domain.com/producten/ (producten archive)
- www.domain.com/producten/category (producten category archive)
- www.domain.com/producten/category/subcategory (producten subcategory archive)
- www.domain.com/producten/category/post_tile (single page for post in main category)
- www.domain.com/producten/category/subcategory/post_tile (single page for post in sub category)
I can’t get it to work. I first tried the “custom post type permalinks” plugin. Which did not work and gave me 404 errors. Even after flushing the permalinks more than a few times.
After that I tried manually changing the permalink by using “filter_post_type_link”. But I just can’t get it to work.
You can find my code for registering the post type on the taxonomy here -> http://pastebin.com/DMfA21qb
Hope someone can help me.
Take a look at this post
How to create a permalink structure with custom taxonomies and custom post types like base-name/parent-tax/child-tax/custom-post-type-name
Accompanied by:
How to change permalink structure for custom post type and it’s taxonomies?
and
Custom post types, taxonomies, and permalinks
It will cover what you are trying to do for /category/subcategory/othersubcategory/posttitle.
Edit: I implemented this and fixed some issues with a double trailing slash.
Look at this, it works How to fix a double slash in custom permalinks with hierarchical taxonomy’s?
I know it’s not a direct answer, but you could try the MagicFields plugin.
http://magicfields.org/
It makes working with custom post types and taxonomies a lot easier. I don’t know if it is an overkill for your specific requirements though.
Try changing
To