URL rewriting hack for custom post types
-
Hello hello,
I’m pretty much new to the new and awesome feature wordpress released for us it’s latest version: custom post types.
I managed to set them up in the admin, publish some and display them on my blog.
The problem is that even after many hours of playing around and searching online, I can’t find a way to rewrite my URLs in a way that makes sense.
I have about 4 different custom post types and they all share the same categories and sub-categories. I would like the URLs to look like this:
View all posts by post category and type: https://myblog.com/category/category/post_type/
Paginated: https://myblog.com/category/category/post_type/page-2/View a specific post:
https://myblog.com/category/category/post_type/post_id-postname/I have tried to play with the $wp_rewrite array, the create_rewrite_rules hook, the custom_permalink hook, etc. but I can’t make anything actually work the way I want.
I have actually been able to figure a work around to get this structure: https://myblog.com/post_type/category/category/
But then the posts don’t work when I go to: https://myblog.com/post_type/category/category/post_id-postname/
Here is the latest code I have been playing with.
[Large code excerpt removed by moderator per forum rules. Please use the pastebin for all large code excerpts. It works better anyway.]
- The topic ‘URL rewriting hack for custom post types’ is closed to new replies.