MySql query to replace base urls in wordpress posts and pages

12 years ago, July 17, 2012
Reading time: 1 mins

Whenever I am porting my new WordPress application from my development server to the live I face this problem that the urls of the images, etc that are inserted from the editor's browser in the wordpress backend, have the absolute base urls of the current server.

So if I am on my development server, all the images' urls will be attached with the absolute full url of the server too.

The way around I found at the begining was just manually change them going to the edit page on each and every page and post. But its tidious and time consuming so, I found this trick and is really helpful, does all in just a second or two.

UPDATE wp_posts SET post_content = REPLACE(post_content,'DEV_URL','LIVE_URL');

This is a simple sql query which will replace each and every occurance of DEV_URL (may look like or if you are on local machine) with LIVE_URL which is your live site's URL.

This is an SQL query , It can be used on any application and may help in many other case, but for me It was perfect for the wordpress development.

Firefox Icon not displayed for HTML files after Firefox Update
Laxmi Bank’s ATM service
© 2024 Anil Maharjan