How to Replace Old Domain URL in wp_posts Table

mysql replace

I migrated my WordPress website to new domain, so I need to update all image URLs in wp_posts, wp_postmeta, and wp_options table which are still pointing to old domain.

These are the SQL syntaxs to update the tables:

UPDATE wp_posts SET post_content = REPLACE( post_content, 'oldomain.com', 'newdomain.com' );
UPDATE wp_postmeta SET meta_value = REPLACE( meta_value, 'oldomain.com', 'newdomain.com' );
UPDATE wp_options SET option_value = REPLACE( option_value, 'oldomain.com', 'newdomain.com' );
UPDATE wp_posts SET guid = REPLACE( guid, 'oldomain.com', 'newdomain.com' );

mysql replace

2 thoughts on “How to Replace Old Domain URL in wp_posts Table

  1. Excellent…thank you. Only addition I would make is also doing a replace on the “guid” if you had revisions on.

    UPDATE wp_posts SET guid = REPLACE( guid, ‘oldomain.com’, ‘newdomain.com’ );

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.