WordPress MU: Changing Domain Names

There is no automatic built-in method/function in WordPress to change a multi-user WordPress’s domain name. I faced this problem when I tried to add ‘www.’ to the domain name. Hopefully, many people have this problem and give out pretty good solution.

Oremj integrate the DB changes needed into one PHP script, which is quite convenient and works well for me: http://blog.mozilla.org/oremj/2009/10/27/wordpressmu-changing-domain-names/.

define('WP_INSTALLING', true);

$old_domain = 'olddomain.com';
$new_domain = 'newdomain.com';

$query = "UPDATE wp_site SET domain = '$new_domain' where domain = '$old_domain'";

$query = "UPDATE wp_blogs SET domain = REPLACE(domain, '$old_domain', '$new_domain')";

$querystr ="SHOW TABLES LIKE 'wp_%_options'";

$tables = $wpdb->get_results($querystr, ARRAY_N);

echo count($tables);
$query = "";
if ($tables){
  foreach ($tables as $table){
    $query = 'UPDATE '.$table[0]." SET option_value = REPLACE(option_value,'$old_domain','$new_domain')";

After modifying and running this PHP script (I did in by $ php script.php on the server side), remember changing the “DOMAIN_CURRENT_SITE” in your WordPress’s wp-config.php.

Eric Ma

Eric is a systems guy. Eric is interested in building high-performance and scalable distributed systems and related technologies. The views or opinions expressed here are solely Eric's own and do not necessarily represent those of any third parties.

One comment:

Leave a Reply

Your email address will not be published. Required fields are marked *