Wordpress - Regenerate Slugs From Title of Posts

Yes, it is possible.

Sample code, has to be tested and refined:

// get all posts
$posts = get_posts( array (  'numberposts' => -1 ) );

foreach ( $posts as $post )
{
    // check the slug and run an update if necessary 
    $new_slug = sanitize_title( $post->post_title );
    if ( $post->post_name != $new_slug )
    {
        wp_update_post(
            array (
                'ID'        => $post->ID,
                'post_name' => $new_slug
            )
        );
    }
}

I just made this up, there are probably some errors and egde cases, but it should give you an idea. Also, this may take a while, so it could be useful to split the update into smaller chunks.


This plugin also does the job: http://www.jerrytravis.com/598/wordpress-plugin-to-generate-post-slugs

However, as it only does it for posts which don't have a slug yet, if you need to regenerate slugs edit the following line in the plugin:

if ($post->post_name == "") {

for example, you could change it to:

if (true) {

Tags:

Slug

Get Posts