Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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!

share|improve this question
    
What are the desired before and after states? I just recently had to go through an update of urls because I messed up in the migration process by creating duplicate URLS for posts with the same titles. I had to create a PHP script that first read the entry from the database, then modified the string in question, then updated the database entry where it was pulled from. My script wouldn't necessary work in this scenario, but that's why I asked what your before and after states are. –  Brent Aug 16 '12 at 5:08
    
This is an example of what mine look like: mysite.com/finding_romance when it should be: mysite.com/finding-romance-on-a-beach-in-france –  D12Eminem989 Aug 16 '12 at 5:38
add comment

2 Answers

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));
}
share|improve this answer
add comment

It would seem the importer did not fully import slug names, or had a slug limit, which caused this effect.

You can run a query to update all the slugs based on article names, which is the default approach by WordPress as well when generating the initial slug (referenced as *post_name* in the DB table *wp_posts*).

It is recommended to first sanitize your post names of course (using sanitize_title_with_dashes() for this purpose seems apropriate.

A short snippet that performs an update to the slug of all posts was created for the purpose of this question and can be seen at https://github.com/Clorith/wp-slug-update if you don't wish to start touching upon the code aspect your self.

share|improve this answer
    
Welcome to WordPress Answers! An answer should be more than just a link to an external site. Please add a solution. –  toscho Aug 16 '12 at 19:28
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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