I have been digging the code for days and no solution. 🙁
I have a Custom Post Type and two different Taxonomies.
It is possible to achieve the following permalink structure (with add_rewrite_rule, mod_rewrite or post_type_link post type filter) or not?
mysite.com/post-type-slug/post1
mysite.com/post-type-slug/taxonomy1-term
mysite.com/post-type-slug/taxonomy2-term
not required, but would be nice to create these URLs too
mysite.com/post-type-slug/taxonomy1-term/taxonomy1-subterm - if each tax. is hierarchical
mysite.com/post-type-slug/taxonomy-term1/post1 - display posts under tax. URLs
Do you have any idea?
I’ll look into the last two soon but for the top 3 you could do the following:
mysite.com/post-type-slug/post1:
This defaults to the post type name you specify when registering it but can be altered by changing the
rewrite
argument in theregister_post_type()
call.mysite.com/post-type-slug/taxonomy1-term:
I don’t think you can easily get the hyphen between the taxonomy name and the term name if that’s what you mean but you can do the following:
Which will give you a URL like this:
mysite.com/post-type-slug/taxonomy-slug/term
I wasn’t too sure from your question but if you don’t want the
taxonomy-slug
to be there then you’re out of luck, you can’t have the same slug as your post type or another taxonomy as it won’t know what term is from which taxonomy and what’s a post.To get the heirarchical terms URL do this:
Which gives you
mysite.com/post-type-slug/taxonomy-slug/term/sub-term
Note:
If it helps setting
slug
to false gets rid of it altogether so you’d get:mysite.com/term/sub-term