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've browsed tons of Q/A on stackexchange, google, wordpress forums... but haven't found yet a definitive answer to what looks like to be a common issue since the introduction of custom post types.

I've set my permalinks structure from Wordpress admin permalink settings page as:

/%post_id%/%post_name%/

since this is a good practice to improve database performance

however, I noticed my custom post types (I have several in one configuration) still appear as:

%cpt_slug%/%post_name%/

while what I really want is

%cpt_slug%/%post_id%/%post_name%/

and actually would love if it could also work as

%cpt_slug%/%post_id%/%taxonomy%/%post_name%/

but as for now, I would like to get the post_id work in the cpt structure

how to achieve this?

there was a wordpress plugin but apparently it was withdrawn because had some issues (and anyway is no longer mantained)

share|improve this question
    
>"since this is a good practice to improve database performance" Note that this will no longer be the case in WordPress 3.3 which is being released imminently. You can just use /%postname%/ without performance penalty. –  Stephen Cronin Nov 16 '11 at 23:30
    
oh yeah I actually just read that after posting, good anyway from a SEO point of view it would be nice to have the %taxonomy% in the cpt permalink displayed thanks –  Fulvio Nov 17 '11 at 9:38
add comment

2 Answers

up vote 0 down vote accepted
function myrules(){
    add_rewrite_rule('^yourcptslughere/([^/]*)/([^/]*)/([^/]*)/?','index.php?p=$matches[1]&taxonomy=$matches[2]&name=$matches[3]','top');
}
add_action('init','myrules');

Replace the 'yourcptslughere' with what you wanted, and then add that to functions.php then flush your rewrite rules, and the final example you posted should work. I doubt it will be what the_permalink() returns however so you will have to construct the urls yourself, however they should be viewable at those URLs e.g.:

example.com/randomcptslug/123/exampletaxonomy/testpost
share|improve this answer
    
I think you can skip matching the name and taxonomy, when you are already looking up post via post_id. so index.php?p=$matches[1] will be enough. –  Hameedullah Khan Nov 17 '11 at 14:31
    
Indeed! Although I put the whole thing in just encase –  Tom J Nowell Nov 17 '11 at 15:57
add comment

WordPress are working on increasing the performance of Custom Permalink Structures which is supposed to be completed on the next update

share|improve this answer
    
ok, you mean 3.3? that would be awsome –  Fulvio Nov 17 '11 at 9:38
add comment

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.