Archive

Posts Tagged ‘mySQL’

How to Update Your WordPress Database After Changing URLs

April 15th, 2010 Daniel Murphy No comments

Let’s say you are moving your WordPress site from ‘example.com/blog’ to ‘example.com’. In your options panel, you can change your base URL and your site will more or less work, but any internal links inside of posts (including images) will be broken.

Here’s a quick SQL snippet I use for moving my WordPress sites to a new URL.


SET @oldURL = 'example.org/blog';
SET @newURL = 'example.org';
update wp_comments set comment_content = replace(comment_content, @oldURL, @newURL);
update wp_comments set comment_author_url = replace(comment_author_url, @oldURL, @newURL);
update wp_postmeta set meta_value = replace(meta_value, @oldURL, @newURL);
update wp_posts set post_content = replace(post_content, @oldURL, @newURL);
update wp_options set option_value = replace(option_value, @oldURL, @newURL);

Change the URLs on the first two lines, then copy and past that into PHPMyAdmin and you’ll be good to go!

PS- If I’m missing anything, let me know in the comments.

Categories: Web Development Tags: ,