Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm registering a Custom Post Type and in the rewrite array I am trying to do something like this:

'rewrite' => array('slug' => "explore/resources/".$CATEGORY, 'with_front' => false)

I want the rule to 'dynamically' get the post's category name somehow. I also tried using %category% there but it doesn't work either. I need the post's url to represent the entire path/route to it. Any ideas on how to achieve this?

UPDATE: Here is more clarification:

I have a custom post type of 'resources' and these post have several different categories like 'forms', 'mp3' etc. now this Resources area in the site is under another section (that is a page with custom loop for those custom posts) which is called Explore. What I want to achieve is:

domain.com/Explore/Resources/Resource-Category/Resource-Name

or

domian.com/explore/resources/forms/production-form-1

My current rewrite rule in register_post_type() is:

'rewrite' => array('slug' => "explore/resources", 'with_front' => false).

Thanks!

share|improve this question
    
@Amit: It's not clear what you are after. I'm not sure what you mean when you say "'dynamically' get the posts's category name somehow". Can you please explain in more depth? Also, can you please tell us what your Custom Post Type is and give several example URLs that you would like your system to produce? –  MikeSchinkel Aug 19 '10 at 21:47
    
@Mike, I have a custom post type of 'resources' and these post have several different categories like 'forms', 'mp3' etc. now this Resources area in the site is under another section (who is a page with custom loop for those custom posts) which is called Explore. what I want to achieve is domain.com/Explore/Resources/Resource-Category/Resource-Name or domian.com/explore/resources/forms/production-form-1. my current rewrite rule (in register_post_type()) is 'rewrite' => array('slug' => "explore/resources", 'with_front' => false). Thanks for the fast response! –  Amit Aug 19 '10 at 22:58
    
I'm going to have to do some research on this one, assuming someone else doesn't answer it correctly before I do. –  MikeSchinkel Aug 19 '10 at 23:16
    
@Mike, I just saw the correspondence in the mailing list about taxonomies, custom posts and rewrites and your trac suggestion about the new controller, I guess that my issue is similar to what is described there so I´ll jut have to wait for some newer, more fit implementation. –  Amit Aug 22 '10 at 17:54
    
Any chance you could make your WordPress database available somehow so that I could load it and not have to recreate your data in order to test this? You could post the SQL dump file as a private gist at gist.github.com... –  MikeSchinkel Aug 23 '10 at 4:46
show 1 more comment

1 Answer 1

up vote 2 down vote accepted

You could use my plugin:

http://wordpress.org/extend/plugins/custom-post-permalinks/

That will only work if it's a non-hierarchical post type.

If it's hierarchical, you're going to have to register the permastruct yourself. This is a huge ordeal which I don't have the time to write out at the moment. You can look at the code in my plugin above and try to work it out for yourself. Some pointers:

  • In order to get the category into the URL, you're going to have to hook into the 'post_type_link'
  • You'll also have to hook into 'parse_request' to make sure the post type is recognized.
share|improve this answer
    
tried it and it doesn't let me add the %category%, my post types use it and are non-hierarchical. –  Amit Aug 19 '10 at 22:52
    
Are you sure you registered categories for the post type? My plugin only does categories, not other hierarchical taxonomies. –  John P Bloch Aug 20 '10 at 2:25
    
You know, your question/response made me double check the code, and you're right, there was a bug there. I'm sorry about that. Categories should work for you using my plugin now. –  John P Bloch Aug 20 '10 at 13:26
    
thanks, this issue is fixed now but now I think I've found another bug and its doesn't let me do something like (only) /%category%/%resource% it instead adds before the %post_type%/ so it ends to be /%post_type%/%category%/%resource%. –  Amit Aug 20 '10 at 16:44
    
Nope, that's intentional. It only does that if your permastruct mirrors the post permastruct. If your custom permastruct is the same as posts, everything breaks. WordPress matches everything against your custom post type instead of posts. They have to differ somehow. –  John P Bloch Aug 20 '10 at 17:08
show 6 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.