0

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)

2
  • >"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. Nov 16, 2011 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
    – unfulvio
    Nov 17, 2011 at 9:38

2 Answers 2

0
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
2
  • 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. Nov 17, 2011 at 14:31
  • Indeed! Although I put the whole thing in just encase
    – Tom J Nowell
    Nov 17, 2011 at 15:57
0

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

1
  • ok, you mean 3.3? that would be awsome
    – unfulvio
    Nov 17, 2011 at 9:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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