Updating WordPress GUIDS

Recently I changed domain name of one of my other WordPress blogs. However after transferring I found that the GUId’s of the old posts were not updated. They were still referencing the old domain. This caused the feed of the new site to show incorrect domains. My initial thought was to to use a plugin, but it would have taken some time to search for the one I required. So the next best thing for me was to do a update on the post table directly from my hosting PHPMyAdmin interface.

A simple way to do it is to use the MySQL ‘REPLACE’ function to change th domain name in the GUID column in the ‘wp_posts’ table. The following code shows a way to accomplish the same. This will replace all GUID column values in the wp_posts table having ‘domain1.com’ as a url with ‘domain2.com’.

UPDATE wp_posts 
   guid = REPLACE(guid,
  where guid like '%domain1.com%'

The ‘REPLACE’ function takes three parameters :

REPLACE(original_string, string_to_replace, string_to_replace_with);

A example is given below.

SELECT REPLACE('https://www.domain1.com', 'domain1.com', 'domain2.com');
-> https://www.domain2.com

So in our above example we are replacing the ‘domain1.com’ string with the ‘domain2.com’ string. Do not confuse REPLACE function with the REPLACE statement, both are different.

Note that when searching for text to replace, MySQL uses case-sensitive match to perform a search for a string to be replaced.

Also it very important that the first parameter to REPLACE here is the column name
and not a pure string, so DO NOT put quotes. If you put quotes to the field name like “guid”, the query will replace the content of that column with the string “guid”.

Also as usual whenever making any changes to the database, always make a backup.

So in conclusion, as I was already at the installation stage and had my hosting cPanel open, this solution was the quickest for me.

Leave a Reply

Your email address will not be published.