the following problem - I want to completly change my post permalink structure to be like this:


It would even be more nice to have a permalink structure like this:


The problem is not that I did not find a work-arround how to achieve this:

add_action('save_post', 'set_slug');

function set_slug($post_id){
    $new_slug = get_post_meta($post_id,'meta_key1', true)."-".get_post_meta($post_id,'meta_key2', true);    
    $post_args = array(
        'ID' => $post_id,
        'post_name' => $new_slug,


The problem is that I am expecting a very, very large number of posts and I am afraid that the performance will be really bad? So how can I make sure, that WordPress will find the correct correspondig post fast, although using such an exotic permalink structure? Or is there (for what reason?) no performance problem to be expected?

1 Answer 1


Your code is setting the slug of the post to your custom meta string. That work is done on the admin side and so shouldn't effect your viewers much.

WordPress will use that slug more or less directly to construct an url and/or load a page. What you have done is not different from hand-writing a slug in the "Permalink" portion of the post form. Performance should be no different than the performance when doing that.

If those meta keys are changing a lot though you could end up having trouble. WordPress will track the slug changes and load the appropriate page but if the slugs are changing constantly you could create a circumstance where a lot of work is required to find the appropriate page.

You are afraid that the performance will be really bad or you know that it is really bad? Be wary of premature optimization.

  • Hello thank you for your answer. As soon as a permalink is created it is very likely not to change anymore. There is currently no performance problem, the site is under development. However - any idea how to do "premature optimization" on the permalink structure of WP? Is there a hook or something for detecting the correct post?
    – Blackbam
    Commented Aug 16, 2013 at 12:15
  • You don't want to do "premature optimization". It means something like "optimize where you don't need to". You end up wasting time to gain insignificant performance.
    – s_ha_dum
    Commented Aug 16, 2013 at 13:02
  • Ah ok now I think I understand what this term means :D
    – Blackbam
    Commented Aug 20, 2013 at 18:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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