I have a custom post type ‘news’ and a taxonomy ‘category-news’.
I would like to get this permalinks:
www.domain.com/news -------------> list of all news
www.domain.com/news/sport -------> list of all sport news
www.domain.com/news/sport/post --> the post
www.domain.com/news/2014 --------> list of all news of year 2014
www.domain.com/news/sport/2014 --> list of all sport news of year 2014
www.domain.com/news/page/2 ------> second page of pagination news
www.domain.com/news/sport/page/2 -> second page of pagination sport news
is it posible? How can I do it?
Thanks.
Here is some code I’ve cooked up based on some code I’ve already been working on. My original code works okay, however I haven’t tested this code because I haven’t seen your code. Here is what you need to do:
on your post type definition, set the
rewrite
argument to falsePut the following code after your post type code:
I’ll post an in depth explanation after work. Let me know if it works for you
EDIT: Okay, here is the basic rundown:
wpse136458_rewrite_api
is the heart of how this works. It basically creates an array of permalink structures made from rewrite tags that follow the rules you specified, then creates the rewrite rules from those structures, using the helper functionsstruct_to_query
(creates the query string) andstruct_to_regex
(creates the regex). The first line of the function, which I just added, creates a rewrite tag for yourcategory-news
taxonomy and the last line that callsadd_permastruct
creates a permastruct that WP uses for specificnews
posts.wpse136458_create_permalink
is a callback to thepost-type_link
filter that takes thatnews
permalink and fills it in with the right data, like the category and the postnameYou can do this permalink by simply getting a plugin or just using a sample theme which is created to explain about custom post permalink structure and parameters.
many sample codes i tried, but none helped me to solve the issue of setting s permalink for my custom post types, i just used the custom post type permalink plugin , later come to know the custom post type theme.
http://kvcodes.com/2014/03/custom-post-type-and-taxonomy-permalink-creation/
This may help you.