I have following structure in my website:
- I have a post type called Destination and slug of post type is “destination“.
So I can access destinations archive page using following url: domain.com/destination. - Now the default blog posts are related to a single destination. For example i have a blog post called places to visit in london. So I have to relate this post to london destination. Which I am storing in my post meta.
Which is easy and I have done it.
But the problem is I need permalink structure in following way.
Destination archive page: domain.com/destination
Single blog page: domain.com/destination/london/blog/places-to-visit-in-london.
I have used WP rewrite API for this. I have followed this artical from tuts plus.
You can find my code on pastbin:
http://pastebin.com/g74zZYUk
I have simply created two tags (%destination_cpt% and %destination_name% )
And those tags works fine and post links works like it should.
But when I open the blog post in frontend it gives me 404 error:
domain.com/destination/london/blog/places-to-visit-in-london
Due to destination slug exists as a post type.
- If we use destinationsxyz as a first slug for default blog post, then default blog post and destination archive page archive page works fine.
But then if we write any first or second or third level wrong url like domain.com/abc or domain.com/abc/xyz or domain.com/abc/pqr/xyz then it leads to default blog page (which we set in settings->reading) of site but actually it should lead to 404 page and now only and only if you use wrong url having 4 levels like domain.com/des/abc/xyz/pqr/efg, it will lead to 404 page.
This happens in default WorrdPress installation with default WP theme (twentysixteen) with no plugin installed or no other extra piece of code theme.
Any help is appreciated.
Thanks in advance.