Bulk Update Absolute URLs in Post Content Using SQL After WordPress Migration

by | February 11, 2023 | SQL, Website Development

This page may contain affiliate links to recommended products or services. If you choose to purchase after clicking a link, I may receive a commission at no additional cost to you.

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

Step 1:
Access your website’s database. Most of the time that’s going to be PHPMyAdmin.

Step 2:
Navigate to your website’s database. Ensure you’re running the SQL query against the database your website is actually using.

Step 3:
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.

Example:

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.

Floyd Hartford is a website developer from southern Maine. He's focused on creating and building WordPress websites and loves spending time digging into code like HTML, CSS, scss, jQuery, PHP, and MySQL.

0 Comments

Submit a Comment

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

eleven − 4 =

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Looking for WordPress Help?

I’m a freelance web developer specializing in small business and corporate marketing websites.

Pin It on Pinterest