Updating guid in Your WordPress Database
I sent a code snippet earlier today and realized. Duh. I should be blogging this.
Here is some code that I have used to update the guid in my wp_posts table. Replace ‘example.com’ with whatever your base url is for your WordPress installation.
Two update queries, one for posts and one for pages. This only updates published posts and ones which don’t have the guid set yet (remove the guid = ” line to replace existing guid values).
update wp_posts
set guid = concat('http://www.example.com/?p=',ID)
where guid = ''
and post_status = 'publish'
and post_type = 'post';
update wp_posts
set guid = concat('http://www.example.com/?post_id=',ID)
where guid = ''
and post_status = 'publish'
and post_type = 'page';
Update: Also Change Your Site URL in Posts in SQL
I have recently been using a different method when moving sites to update the guid and also to do a search and replace within posts and pages for the url of your site. This is necessary when changing your site url since uploaded image references in your posts are set to the absolute url.
/* Use this to update the guid url */ UPDATE wp_posts SET guid = REPLACE ( guid, 'http://www.example-old-url.com', 'http://www.example-new-url.com'); /* Use this to update urls in posts, good for images! */ UPDATE wp_posts SET post_content = REPLACE ( post_content, 'http://www.example-old-url.com', 'http://www.example-new-url.com');




