Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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