Support » Fixing WordPress » Bulk Regenerate Permalinks

  • Does anyone know how I would go about regenerating permalinks? I have a situation where I need to change titles for every post in a custom post type to a custom meta field in the post. I’ve done quite a bit of searching, but I can’t seem to find anything that does the job. All went well for the title and slug…

    $new_slug = sanitize_title( get_the_title() );
    $my_post = array();
    $my_post['ID'] = get_the_id();
    $my_post['post_title'] = esc_attr( get_post_meta( get_the_id(), 'projectSubTitle', true ) );
    $my_post['post_name'] = $new_slug;
    wp_update_post( $my_post );

    Sorry to say, I’m not sure how permalinks are created I guess. I thought simply saving my permalink settings in wp-admin permalink settings would update my htaccess and life would be all good. Unfortunately, the old permalinks remain. I have verified that the slugs have changed in the database. Am I out of luck here…? I guess I could go into each post, remove the permalink and let wordpress generate a new one. Lot’s of posts… I’d like to avoid doing that if at all possible.

    Any help or guidance is much appreciated!!

Viewing 2 replies - 1 through 2 (of 2 total)
  • It appears from the code you posted that you assigned $new_slug based on the original title and then changed the title after that. That seems to be the wrong order to me.

    Oh! good catch. I actually ran that twice, once without the post_name bit, then I added that in later so that’s why that worked for me. I’ve changed the order. Thanks for catching that!

    I am still wondering how to change the permalinks if anyone has any input on that.


Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Bulk Regenerate Permalinks’ is closed to new replies.