WordPress tends to use absolute URLs quite a bit for page and post content for things like links and image references. That’s all good and well when your site is on a stable domain that’s not changing. However, it’s necessary to update those absolute URL domain references if or when you migrate WordPress to a new domain. Otherwise, all of those absolute URL references will be broken. In this post, learn how to bulk update absolute URLs in post content after a WordPress migration using a simple SQL command.
WordPress post content is stored in the database. That means you can use SQL to batch search and replace the strings of text that need to be updated. It’s a lot easier to run a SQL query at the database level and update as much as you can all at once than it is to edit each piece of content individually and perform manual updates.
Batch Search and Replace Absolute URLs Using SQL
Access your website’s database. Most of the time that’s going to be PHPMyAdmin.
Navigate to your website’s database. Ensure you’re running the SQL query against the database your website is actually using.
Run this SQL query:
UPDATE wp_posts SET post_content=(REPLACE (post_content, 'old-text','new-text'));
Make sure you’re using the name of your WordPress site’s post table. The example above shows the post table with the default prefix, however, your website may be using a different table name.
UPDATE wp_posts SET post_content=(REPLACE (post_content, 'http://dev.example.com/','https://example.com/'));
PHPMyAdmin will alert you to a successful or failed command and inform you how many rows were affected.