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 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:


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?


share|improve this question
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
add comment

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).

share|improve this answer
I don´t want to use too many plugins. Sorry. –  user1635 Jan 18 '11 at 21:55
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
@JohnPBloch The custom-post-permalinks that suggested here worked great, but now it is no longet available in the plugin repository and the plugin does not work with WP3.4. –  Maor Barazany Jul 25 '12 at 12:06
show 1 more comment

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:


Results in:


Good job!

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

share|improve this answer
This plugin no longer works in WP3.4 and also not available in the repository. Are there other implementation ideas for this issue? –  Maor Barazany Jul 25 '12 at 12:12
@MaorBarazany patches welcome I assume :) –  kovshenin Jul 26 '12 at 11:34
add comment

Your Answer


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