I recently converted a site from Moveable Type to WordPress and noticed that the permalinks for each post are short, cut off and have underscores in them.

What I am looking to do is if there is a script or SQL command I can run to mass change each posts permalink to the default permalink it would have normally generated based on the post title.

Thanks in advance!

2 Answers
2

Maybe this doesn’t answer your question… but maybe you can adapt it to suit by changing what you put into $slug.

Try this, which should loop over posts and reset the slug to match the post name. For pages, add 'post_type' => 'page' to the array passed to get_posts().

$posts = get_posts(array('posts_per_page' => -1));

foreach ($posts as $post) {
    $slug = sanitize_title(strtolower($post->post_title));
    $slug = wp_unique_post_slug($slug, $post->ID, $post->post_status, $post->post_type, $post->post_parent);

    wp_update_post(array('ID' => $post->ID, 'post_name' => $slug));
}

Tags:

Leave a Reply

Your email address will not be published. Required fields are marked *