Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // change this this to strip old slugs if needed:
- //update wp_posts set post_name = '' where guid like '%.asp'
- set_time_limit(20000);
- /** Loads the WordPress Environment and Template, allowing wp functions like the_title() */
- define('WP_USE_THEMES', false);
- require('./wp-blog-header.php');
- function bleach($which)
- {
- $result = sanitize_title(get_the_title($which));
- return $result;
- }
- $dbhost = 'localhost';
- $dbuser = 'username';
- $dbpass = 'pass';
- $dbname = 'db';
- $sql = 'SELECT ID, post_title' . ' FROM `wp_posts`' . ' WHERE post_status = "publish"' . " and post_name = '' " . ' order by ID asc';
- $db = mysql_connect($dbhost, $dbuser, $dbpass) or die('Could not connect: ' . mysql_error());
- mysql_select_db($dbname);
- $result = mysql_query($sql) or die('<strong>Query failed: ' . mysql_error());
- while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
- $id = $row['ID'];
- $title = $row['post_title'];
- $clean_slug = rawurlencode(bleach($id));
- echo "ID<em>:{$row['ID']} " . "post_title : {$title} " . "sanitized : {$clean_slug} <br>";
- $sql_u = "UPDATE `wp_posts` SET post_name = '" . $clean_slug . "' " . 'WHERE ID = ' . $id;
- echo '<strong>QUERY:</strong>' . $sql_u . '<br>';
- mysql_query($sql_u) or die('ERROR: ' . mysql_error());
- flush();
- }
- echo "</em></strong>";
- mysql_close($db);
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement