Revision: 42615
Updated Code
at March 8, 2011 06:36 by gryzzly
Updated Code
<?php define('BASEPATH',''); // just a helper func to see how long it took to process slugs function microtime_float(){ list($usec, $sec) = explode(" ", microtime()); return ((float)$usec + (float)$sec); } $time_start = microtime_float(); // replace %root% and %secret% with your database credentials $db = mysql_connect('localhost', 'root', 'secret'); // replace %wordpress_db% with your database mysql_select_db('wordpress_db', $db); $sql=""; // this dictionary is copied from the source of http://mywordpress.ru/plugins/rustolat/ // which is great, but only works for new posts // in the situtation when I had > 500 posts it was easier to write this script // than to go one by one updating slugs $iso = array( "��"=>"YE","��"=>"I","��"=>"G","��"=>"i","�"=>"#","��"=>"ye","��"=>"g", "��"=>"A","��"=>"B","��"=>"V","��"=>"G","��"=>"D", "��"=>"E","��"=>"YO","��"=>"ZH", "��"=>"Z","��"=>"I","��"=>"J","��"=>"K","��"=>"L", "��"=>"M","��"=>"N","��"=>"O","��"=>"P","� "=>"R", "�¡"=>"S","�¢"=>"T","�£"=>"U","�¤"=>"F","�¥"=>"X", "�¦"=>"C","�§"=>"CH","�¨"=>"SH","�©"=>"SHH","�ª"=>"'", "�«"=>"Y","�¬"=>"","Ã�ÂÂ"=>"E","�®"=>"YU","�¯"=>"YA", "�°"=>"a","�±"=>"b","�²"=>"v","�³"=>"g","�´"=>"d", "�µ"=>"e","��"=>"yo","�¶"=>"zh", "�·"=>"z","�¸"=>"i","�¹"=>"j","�º"=>"k","�»"=>"l", "�¼"=>"m","�½"=>"n","�¾"=>"o","�¿"=>"p","��"=>"r", "��"=>"s","��"=>"t","��"=>"u","��"=>"f","��"=>"x", "��"=>"c","��"=>"ch","��"=>"sh","��"=>"shh","��"=>"", "��"=>"y","��"=>"","��"=>"e","��"=>"yu","��"=>"ya","�«"=>"","�»"=>"","�"=>"-" ); // this is a name of file that will be generated to use later to actually update our DB // it can be anything you want and by default it will be created in the same directory // where this script is $myFile = "slugs_fix.sql"; $fh = fopen($myFile, 'w') or die("can't open file"); # slugs $q = mysql_query("select * from wp_posts where post_status = 'publish' and post_type = 'post'", $db); while ($row=mysql_fetch_assoc($q)){ $slug = $row["post_name"]; $id = $row["ID"]; // post_name is url-encoded � it's stored in a format // such as %D1%85%D0%B2%D0%BE%D1%81%D1%82 $slug = urldecode($slug); // translate the string $slug = strtr($slug, $iso); $sql .= "update wp_posts set post_name = '" . $slug . "' where id = '" . $id . "'; \n"; $stringData = $sql; fwrite($fh, $stringData); $sql=""; $slug=""; } mysql_close($old); fclose($fh); $time_end = microtime_float(); $time = $time_end - $time_start; echo "Transliterated slugs in $time seconds\n"; // okay, the file is written // and now it can be used like this: // mysql -u root -p wordpress_db < slugs_fix.sql // after issuing this command your slugs should be updated
Revision: 42614
Updated Code
at March 8, 2011 06:35 by gryzzly
Updated Code
<?php define('BASEPATH',''); // just a helper func to see how long it took to process slugs function microtime_float(){ list($usec, $sec) = explode(" ", microtime()); return ((float)$usec + (float)$sec); } $time_start = microtime_float(); // replace %root% and %secret% with your database credentials $db = mysql_connect('localhost', 'root', 'secret'); // replace %wordpress_db% with your database mysql_select_db('wordpress_db', $db); $sql=""; // this dictionary is copied from the source of http://mywordpress.ru/plugins/rustolat/ // which is great, but only works for new posts // in the situtation when I had > 500 posts it was easier to write this script // than to go one by one updating slugs $iso = array( "Ã�"=>"YE","Ã�"=>"I","Ã�"=>"G","�"=>"i","�"=>"#","�"=>"ye","�"=>"g", "Ã�"=>"A","Ã�"=>"B","Ã�"=>"V","Ã�"=>"G","Ã�"=>"D", "Ã�"=>"E","Ã�"=>"YO","Ã�"=>"ZH", "Ã�"=>"Z","Ã�"=>"I","Ã�"=>"J","Ã�"=>"K","Ã�"=>"L", "Ã�"=>"M","Ã�"=>"N","Ã�"=>"O","Ã�"=>"P","à"=>"R", "á"=>"S","â"=>"T","ã"=>"U","ä"=>"F","ÃÂ¥"=>"X", "æ"=>"C","ç"=>"CH","è"=>"SH","é"=>"SHH","ê"=>"'", "ë"=>"Y","ì"=>"","ÃÂ"=>"E","î"=>"YU","ï"=>"YA", "ð"=>"a","ñ"=>"b","ò"=>"v","ó"=>"g","ô"=>"d", "õ"=>"e","�"=>"yo","ö"=>"zh", "÷"=>"z","ø"=>"i","ù"=>"j","ú"=>"k","û"=>"l", "ü"=>"m","ý"=>"n","þ"=>"o","ÿ"=>"p","�"=>"r", "�"=>"s","�"=>"t","�"=>"u","�"=>"f","�"=>"x", "�"=>"c","�"=>"ch","�"=>"sh","�"=>"shh","�"=>"", "�"=>"y","�"=>"","�"=>"e","�"=>"yu","�"=>"ya","«"=>"","»"=>"","�"=>"-" ); // this is a name of file that will be generated to use later to actually update our DB // it can be anything you want and by default it will be created in the same directory // where this script is $myFile = "slugs_fix.sql"; $fh = fopen($myFile, 'w') or die("can't open file"); # slugs $q = mysql_query("select * from wp_posts where post_status = 'publish' and post_type = 'post'", $db); while ($row=mysql_fetch_assoc($q)){ $slug = $row["post_name"]; $id = $row["ID"]; // post_name is url-encoded � it's stored in a format // such as %D1%85%D0%B2%D0%BE%D1%81%D1%82 $slug = urldecode($slug); // translate the string $slug = strtr($slug, $iso); $sql .= "update wp_posts set post_name = '" . $slug . "' where id = '" . $id . "'; \n"; $stringData = $sql; fwrite($fh, $stringData); $sql=""; $slug=""; } mysql_close($old); fclose($fh); $time_end = microtime_float(); $time = $time_end - $time_start; echo "Transliterated slugs in $time seconds\n"; // okay, the file is written // and now it can be used like this: // mysql -u root -p wordpress_db < slugs_fix.sql // after issuing this command your slugs should be updated
Revision: 42613
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at March 8, 2011 06:33 by gryzzly
Initial Code
<?php define('BASEPATH',''); // just a helper func to see how long it took to process slugs function microtime_float(){ list($usec, $sec) = explode(" ", microtime()); return ((float)$usec + (float)$sec); } $time_start = microtime_float(); // replace %root% and %secret% with your database credentials $db = mysql_connect('localhost', 'root', 'secret'); // replace %wordpress_db% with your database mysql_select_db('wordpress_db', $db); $sql=""; // this dictionary is copied from the source of http://mywordpress.ru/plugins/rustolat/ // which is great, but only works for new posts // in the situtation when I had > 500 posts it was easier to write this script // than to go one by one updating slugs $iso = array( "Є"=>"YE","І"=>"I","Ѓ"=>"G","Ñ–"=>"i","â„–"=>"#","Ñ”"=>"ye","Ñ“"=>"g", "Ð"=>"A","Б"=>"B","Ð’"=>"V","Г"=>"G","Д"=>"D", "Е"=>"E","Ð"=>"YO","Ж"=>"ZH", "З"=>"Z","И"=>"I","Й"=>"J","К"=>"K","Л"=>"L", "Ðœ"=>"M","Ð"=>"N","О"=>"O","П"=>"P","Ð "=>"R", "С"=>"S","Т"=>"T","У"=>"U","Ф"=>"F","Ð¥"=>"X", "Ц"=>"C","Ч"=>"CH","Ш"=>"SH","Щ"=>"SHH","Ъ"=>"'", "Ы"=>"Y","Ь"=>"","Ð"=>"E","Ю"=>"YU","Я"=>"YA", "а"=>"a","б"=>"b","в"=>"v","г"=>"g","д"=>"d", "е"=>"e","Ñ‘"=>"yo","ж"=>"zh", "з"=>"z","и"=>"i","й"=>"j","к"=>"k","л"=>"l", "м"=>"m","н"=>"n","о"=>"o","п"=>"p","Ñ€"=>"r", "Ñ"=>"s","Ñ‚"=>"t","у"=>"u","Ñ„"=>"f","Ñ…"=>"x", "ц"=>"c","ч"=>"ch","ш"=>"sh","щ"=>"shh","ÑŠ"=>"", "Ñ‹"=>"y","ÑŒ"=>"","Ñ"=>"e","ÑŽ"=>"yu","Ñ"=>"ya","«"=>"","»"=>"","—"=>"-" ); // this is a name of file that will be generated to use later to actually update our DB // it can be anything you want and by default it will be created in the same directory // where this script is $myFile = "slugs_fix.sql"; $fh = fopen($myFile, 'w') or die("can't open file"); # slugs $q = mysql_query("select * from wp_posts where post_status = 'publish' and post_type = 'post'", $db); while ($row=mysql_fetch_assoc($q)){ $slug = $row["post_name"]; $id = $row["ID"]; // post_name is url-encoded – it's stored in a format // such as %D1%85%D0%B2%D0%BE%D1%81%D1%82 $slug = urldecode($slug); // translate the string $slug = strtr($slug, $iso); $sql .= "update wp_posts set post_name = '" . $slug . "' where id = '" . $id . "'; \n"; $stringData = $sql; fwrite($fh, $stringData); $sql=""; $slug=""; } mysql_close($old); fclose($fh); $time_end = microtime_float(); $time = $time_end - $time_start; echo "Transliterated slugs in $time seconds\n"; // okay, the file is written // and now it can be used like this: // mysql -u root -p wordpress_db < slugs_fix.sql // after issuing this command your slugs should be updated
Initial URL
Initial Description
While working on the iteration of a blog with russian contents we had to change the slugs from cyrillic to transliterated russian. [RusToLat](http://mywordpress.ru/plugins/rustolat/) is a great plugin that does just that, but unfortunately it only does the transliteration for new or "edited" posts (i.e. you have to open the post at least once and "edit" the permalink, then it will be transliterated). Since this blog more than 500 posts this manual updating wasn't an option so we wrote this simple script. Maybe it will save somebody some time. You'd probably better back-up your database before updating it (google for mysqldump syntax).
Initial Title
Transliterate existing cyrillic slugs (post_name) in wordpress
Initial Tags
wordpress
Initial Language
PHP