I´m using the following code to create a new post type:

/* Create custom post type: "Tilbud" */
register_post_type('tilbud', array(
'label' => __('Tilbud'),
'public' => true,
'show_ui' => true,
'capability_type' => 'post',
'hierarchical' => false,
'rewrite' => array('slug' => '???'),
'query_var' => false,
'taxonomies' => array('post_tag','category'),
'supports' => array('title'),
'register_meta_box_cb' => 'add_tilbud_metaboxes',
));

I would like the premalink of these custom posts to contain the custom post type name followed by the post category:

.../custom-post-type-name/post-category/post-title/

I´m aware that I use the rewrite argument to add a slug, but I don´t know what to write in order to insert the post type name and category name dynamically.

Any ideas?

Thanks!

link|improve this question
1  
I don't have time to implement the full solution now, but this post I wrote should get you started, vocecommunications.com/blog/2010/11/…. You should be able to modify the filter_post_type_link() method to add the %category% permastructure tag and have it replace it with the slug from the first category. – prettyboymp Jan 18 '11 at 22:40
feedback

2 Answers

up vote 5 down vote accepted

My plugin here: http://wordpress.org/extend/plugins/custom-post-permalinks/ does exactly what you need. All you need to do with that code is remove the query_var argument and change the rewrite slug to 'tilbud' (or whatever you'd like to have in the permastruct).

link|improve this answer
I don´t want to use too many plugins. Sorry. – user1635 Jan 18 '11 at 21:55
1  
Then look at my plugin for ideas. I'm telling you, it does EXACTLY what you've asked about. – John P Bloch Jan 18 '11 at 21:59
I´ve looked at your plugin and I can say for sure its way beyond my level of understanding ;-) – user1635 Jan 24 '11 at 14:23
Hey John, your plug-in rocks! – azure_ardee Mar 7 '11 at 3:41
feedback

Just FYI the plugin mentioned above is awesome. Not only do you get permalinks for custom post types, but it supports custom taxonomy too, so something like this is legit:

/games/%game_category%/%game%

Results in:

/games/racing/need-for-speed/

Good job!

(couldn't post this as a comment for some reason, sorry)

link|improve this answer
feedback

Your Answer

 
or
required, but never shown