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 SET guid = REPLACE(guid, 'domain1.com', 'domain2.com') 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
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.