ecommerce,

Change WordPress domain URL through WP-CLI

Jan 01, 2022 · 1 min read · Post a comment

While migrating your WordPress site or syncing the production database with staging you need to change the domain URL from the database. Instead of crawling within the WP databases, I will show you how to change WP domain URL through WP-CLI which is a more effective way with a simple command.

Prerequisites

  • WordPress site
  • WP-CLI

Solution

To change the domain URL through WP-CLI run the following command:

wp search-replace https://old-url.com https://new-url.com --all-tables;

The command will search for the old-url through the all database tables and replace it with the new-url domain. To see the changes immediately flush the WP cache with:

wp cache flush;

Now open your browser and navigate to your new domain URL.

Conclusion

Feel free to leave a comment below and if you find this tutorial useful, follow our official channel on Telegram.