Skip to content

Instantly share code, notes, and snippets.

@zetrider
Created September 13, 2019 16:54
Show Gist options
  • Save zetrider/35bd94060a606ce5ca742457aed8081e to your computer and use it in GitHub Desktop.
Save zetrider/35bd94060a606ce5ca742457aed8081e to your computer and use it in GitHub Desktop.
old domain to new domain
<?
global $wpdb;
define('MY_OLD_DOMAIN', 'http://olddomain.ru');
define('MY_NEW_DOMAIN', 'http://newdomain.ru');
function myWalkCallback(&$item, $key)
{
$item = str_replace(MY_OLD_DOMAIN, MY_NEW_DOMAIN, $item);
}
$rows = $wpdb->get_results("SELECT * FROM wp_options WHERE option_value LIKE '%" . MY_OLD_DOMAIN . "%'");
foreach($rows as $row)
{
$value = @unserialize($row->option_value);
if(!$value)
{
continue;
}
array_walk_recursive($value, 'myWalkCallback');
$wpdb->update('wp_options', ['option_value' => serialize($value)], ['option_id' => $row->option_id]);
if ($wpdb->last_error)
{
echo $wpdb->last_error . '<br>';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment