Skip to content

Instantly share code, notes, and snippets.

@gbaptista
Last active December 12, 2015 09:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save gbaptista/4755251 to your computer and use it in GitHub Desktop.
Save gbaptista/4755251 to your computer and use it in GitHub Desktop.
Mudar o domínio base do Wordpress.
<?php
$mysql_host = 'localhost';
$mysql_user = '';
$mysql_pass = '';
$mysql_base = 'wordpress_database';
$old_domain = 'www.old_domain.com';
$new_domain = 'www.new_domain.com';
if($conn = mysql_connect($mysql_host, $mysql_user, $mysql_pass)) {
mysql_select_db($mysql_base, $conn);
} else {
echo mysql_error(); mysql_close($conn); exit;
}
$replaces = array(
'wp_comments' => array('comment_content'),
'wp_options' => array('option_value'),
'wp_postmeta' => array('meta_value'),
'wp_posts' => array('post_content', 'guid')
);
echo "\nMigrating $old_domain to $new_domain...\n";
foreach ($replaces as $table => $columns) {
foreach ($columns as $column) {
echo "\n - Migrating {$table}[$column]...\n";
mysql_query("UPDATE {$table} SET {$column}=REPLACE({$column}, '{$old_domain}', '{$new_domain}') WHERE {$column} LIKE '%$old_domain%'");
}
}
echo "\nDone! [$old_domain to $new_domain] =)\n\n";
mysql_close($conn);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment