Advertisement
SergeyBiryukov

Regenerate post slugs

Dec 9th, 2014
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.51 KB | None | 0 0
  1. <?php
  2. require 'wp-load.php';
  3.  
  4. echo "Regenerating post slugs...<br />\n";
  5. $posts = $wpdb->get_results( "SELECT ID, post_title, post_name FROM {$wpdb->posts} WHERE post_status = 'publish'" );
  6. foreach ( (array) $posts as $post ) {
  7.     $post_name = sanitize_title( $post->post_title );
  8.     if ( $post_name !== $post->post_name ) {
  9.         add_post_meta( $post->ID, '_wp_old_slug', $post->post_name );
  10.         $wpdb->update( $wpdb->posts, array( 'post_name' => $post_name ), array( 'ID' => $post->ID ) );
  11.     }
  12. }
  13.  
  14. echo 'All done!';
  15. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement