because sometimes I'm just fucking right
Jun 21
2010

OK, so the question marks may have (probably) came from when I upgraded from MySQL 4 to MySQL 5 not from the WordPress upgrade.  I just didn’t notice when I did the upgrade.  It was a quick thing.  Anyway, I confirmed that the data in the field was actually a question mark combined with another character and then whipped up a simple PHP script to fix it all.  I’ve managed to fix most of the issues but not all.  There are some posts that I may have to edit by hand or just ignore. Oh, and the code below assumes the Zend Framework is in your path.


require_once 'Zend/Loader/Autoloader.php';
$autoloader = Zend_Loader_Autoloader::getInstance();

$db = new Zend_Db_Adapter_Pdo_Mysql(array(
        'host' => 'NOPE',
        'username' => 'NOPE',
        'password' => 'NOPE',
        'dbname' => 'NOPE'));

$sql = 'SELECT ID, post_content FROM wp_posts where post_content like \'%.?%\'';

$result = $db->fetchAll($sql);

$table='wp_posts';

foreach ($result as $row)
{
    $newContent = str_replace('.?', '.', $row['post_content']);
    $wheres = array("ID={$row['ID']}");
    $params = array('post_content' => $newContent);
    $db->update($table, $params, $wheres);
}
 
Jun 17
2010

So I just upgraded to the newest version of WordPress and now most of my old posts have question marks sprinkled through out them.  Grrrr… I know no one actually reads my blog but it’s still irritating. :)   Now I have to write some masterful script that will remove the question marks that don’t below but leave the ones that do.  Or maybe it’s just time to dump the whole thing…