How to update media URL(GUID) on WordPress database?

I’m finishing a new project using WordPress this month and I’m already testing on the production web server, but not always all things goes well when we deploy our project on server, right?

Things misconfigured like database or URLs to images and js can make that our recently site uploaded doesn’t work properly.

I have uploaded my custom theme and database from my local environment to the server, I updated the site URL in the WordPress database with the domain name of my project, then I check the site on the production server to see if all it’s ok, and yes, all looks well.

What’s my problem?

Then I go to test again in another computer, all looks ok but with an exception, the media uploaded through the WordPress admin on my localhost it does not appear.

I had though  that changing the URL in the option table in WordPress it’s all I need to make it run the site on the server, but not. So I needed to do a SQL sentence to update all the URLs of the media files in the database to the domain of the project.

Searching in Google in I found the post “13 Useful WordPress SQL Queries You Wish You Knew Earlier“, where they explains how to update the media URL for any file uploaded using the Worpdress admin.

To update the URL of the media uploaded locally to the new URL we need is change the GUID of each media with a query on our WordPress database.


UPDATE wp_posts SET guid = REPLACE (guid, '', '');




Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s