Changing Domains/Environments in WordPress MU
4 Comments Published December 2nd, 2008 in technology, wordpressI’m working on a WordPress MU blog network and ran accross the need to change the domain that the blogs are running under. This should actually be a fairly common need, for example, if you copy your PROD environment to QA, you’ll probably want to change the blog url from http://blog.com to http://qa.blog.com.
Changing the domain name starts out pretty straightforward:
- edit the “domain” in the wp_site table.
- edit all “domain” entries in the wp_blogs table: UPDATE wp_blogs SET domain = REPLACE(domain,”blog.com”,”qa.blog.com”)
But then, you’ll notice that there’s a lot of hard-coded urls in the wp_#_options table, which exists for every blog in your network.
So, here’s a little PHP file that you can put in the root of your WordPress MU install (or elsewhere). This will loop though these tables and do the replaces you need:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | < ?php require_once('wp-load.php'); $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,"blog.com","qa.blog.com")'; $wpdb->query($query); } } ?> |
The file will output a count of the number of tables that were affected. Ta da
4 Responses to “Changing Domains/Environments in WordPress MU”
- 1 Pingback on Oct 27th, 2009 at 2:12 pm
Great. Do we need to make changes to wp-config.php also?
Regards,
Vivek Dutta Mishra
Hi Vivek,
The wp-config should be configured the first time you install wordpress MU in each environment, and there’s no need to change anything there when copying prod to QA for example.
Take care,
- Boris
This worked wonderfully for me, only thing I had to change was wp-load.php to wp-blog-header.php dont know if this is due to having an older version or not but thought I would mention it so anyone who cant find the wp-load file can try the wp-blog-header file instead.
Thanks for posting this solution
Luke