David Coveney

Resolving WordPress Migration Issue

I’m posting this for the benefit of anyone who experiences a similar problem to mine when moving WordPress from a directory into the web’s root directory.

What happened was that many links and pictures, some placed in there by plugins, others simply links that were typed in, had failed.

I realised that although I’d followed the migration instructions, a lot of things were left poorly sorted. A quick run through of all the tables showed where values were left incorrectly set. To fix this I wrote the following SQL statements and applied them to my database:

update wp_posts set guid = replace(guid,”/wordpress”,””);

update wp_postmeta set meta_value = replace(meta_value,”/wordpress”,””);

update wp_options set option_value = replace(option_value,”/wordpress”,””);

update wp_posts set post_content = replace(post_content,”/wordpress”,””);

These worked a treat.

To use this yourself I’ve done a version below that you can edit – simply replace $$$olddir$$$ with your old directory name (in my case wordpress) and replace $$$newdir$$$ with your new directory name. If your new directory is the root, remove the / at the beginning of each $$$newdir$$$ – see my example above.

A couple of warnings though – first take a backup of your database! Then think carefully – if you don’t know what you’re doing you may well be advised in seeking someone out who does.
update wp_posts set guid = replace(guid,”/$$$olddir$$$”,”/$$$newdir$$$”);

update wp_postmeta set meta_value = replace(meta_value,”/$$$olddir$$$”,”$$$newdir$$$”);

update wp_options set option_value = replace(option_value,”/$$$olddir$$$”,”$$$newdir$$$”);

update wp_posts set post_content = replace(post_content,”/$$$olddir$$$”,”$$$newdir$$$”);

Good luck and have fun!


Posted: 16 October, 2006 at 1:12 PM

Pilates Reformer Dvd says:

Didn’t notice it before…quite clever.


Posted: 9 April, 2009 at 5:42 PM

Wendy says:

Here’s an easier way of moving your wordpress that i found. Looks like you just need to modify your site before you backup your database.



Posted: 9 April, 2009 at 6:02 PM

Dave says:

Whilst that is correct, you can still run into issues with plugins that also store URLs… You also need to do a search and replace on various tables, and then fix the serialisation problems using my serialization fixer that can solve most issues that can cause.

Ultimately, migrating WordPress is far more painful than it should be. I’m looking to fix that properly soon…


Posted: 11 June, 2014 at 11:34 PM

GoLive says:

There is a another easiest way to move/migrate your wordpress site, use a plugin.

Check this one: http://codecanyon.net/item/wp-golive/7793291


Have your say

This site uses Akismet to reduce spam. Learn how your comment data is processed.