/ Published in: PHP
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).
[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).
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<?php // just a helper func to see how long it took to process slugs function microtime_float(){ return ((float)$usec + (float)$sec); } $time_start = microtime_float(); // replace %root% and %secret% with your database credentials // replace %wordpress_db% with your database $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 "��"=>"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"; # slugs $q = mysql_query("select * from wp_posts where post_status = 'publish' and post_type = 'post'", $db); $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 // translate the string $sql .= "update wp_posts set post_name = '" . $slug . "' where id = '" . $id . "'; \n"; $stringData = $sql; $sql=""; $slug=""; } $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