WordPress Uploaded Images – How To Change Absolute URL
Posted on March 29th, 2009 in PHP, Web Development | 3 Comments »
When working with WordPress, you may develop a site on a development server with a different domain than the live server where you intend to deploy the site. When you upload images in a post or a page, WordPress assigns an absolute link as the source of the image. Here is a quick SQL query to run after you migrate your site to the live server so that the absolute URL is updated to reflect the changed domain name.
UPDATE wp_posts set post_content=REPLACE(post_content, 'www.devServer.com/', 'www.liveServer.com/');
3 Responses
Brilliant! Just don’t forget to update the site url (wp_options ID:1) and the blog ‘home’ (wp_options ID:39) once you migrate the data.
As always, great snippet Lee!
-Andre
Nice Lee!
I hit a snag. My theme uses custom fields for images so it took a few to figure out custom fields are in a different place. (Duh!)
UPDATE wp_postmeta SET meta_value= replace(meta_value, ‘http://old-domain.com’, ‘http://new-domain.com’)
Here is another one I found useful as well:
To update WordPress options with the new blog location, use the following SQL command:
UPDATE wp_options SET option_value = replace(option_value, ‘http://www.old-domain.com’, ‘http://www.new-domain.com’) WHERE option_name = ‘home’ OR option_name = ’siteurl’;
Hope all is well!
Impressive Article , I considered it wonderful
I look ahead to more interesting postings like this one. Does Your Blog have a newsletter I can subscribe to for anymore information from you?