Advertisement
Guest User

Untitled

a guest
Jan 9th, 2016
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. <?php
  2.  
  3. // change this to strip old slugs if needed:
  4. //update wp_posts set post_name = '' where guid like '%.asp'
  5. set_time_limit(20000);
  6.  
  7. /** Loads the WordPress Environment and Template, allowing wp functions like the_title() */
  8. define('WP_USE_THEMES', false);
  9. require('./wp-blog-header.php');
  10.  
  11. function bleach($which)
  12. {
  13. $result = sanitize_title(get_the_title($which));
  14. return $result;
  15. }
  16.  
  17. $dbhost = 'localhost';
  18. $dbuser = 'username';
  19. $dbpass = 'password';
  20. $dbname = 'wordpress';
  21.  
  22. $sql = 'SELECT ID, post_title' . ' FROM `wp_posts`' . ' WHERE post_status = "publish"' . " and post_name = '' " . ' order by ID asc';
  23.  
  24. $db = mysql_connect($dbhost, $dbuser, $dbpass) or die('Could not connect: ' . mysql_error());
  25. mysql_select_db($dbname);
  26.  
  27. $result = mysql_query($sql) or die('Query failed: ' . mysql_error());
  28. while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
  29. $id = $row['ID'];
  30. $title = $row['post_title'];
  31. $clean_slug = rawurlencode(bleach($id));
  32.  
  33. echo "ID:{$row['ID']} " . "post_title : {$title} " . "sanitized : {$clean_slug}
  34. ";
  35. $sql_u = "UPDATE `wp_posts` SET post_name = '" . $clean_slug . "' " . 'WHERE ID = ' . $id;
  36. echo 'QUERY:' . $sql_u . '
  37. ';
  38. mysql_query($sql_u) or die('ERROR: ' . mysql_error());
  39. flush();
  40. }
  41. echo "";
  42. mysql_close($db);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement