WordPress Help

Find and replace data in WordPress with WP-CLI

When moving your site to a new domain, you can use commands available in WP-CLI to find and replace the domain name in the database. WP-CLI is a command line tool with simplified commands created specifically for WordPress sites. Besides domain names, you can use these commands to search and replace any other data in the database.

Warning: You should always back up your site before making changes to the database.
Required: You'll need the following to complete these steps:
Note: If you have a VPS or DED Server, you need to install WP-CLI before you can start using it. WP-CLI is not available on our Windows Hosting plans.
  1. Connect to your hosting account with SSH.
  2. Use the bash command ls to list files and folders, and cd and ../ to move through directories until you're in the directory with your WordPress files.
  3. (Optional) To see the replacements to be made without saving them to the database, use the following command:
    wp search-replace 'https://colexample.com' 'https://mycoolnewbusiness.com' --dry-run
    In the command above, you should replace:
    • https://colexample.com with the actual domain name you want to replace.
    • https://mycoolnewbusiness.com with the actual new domain name which should replace the old one.
  4. To replace the data in the database, enter the following command:
    wp search-replace 'https://colexample.com' 'https://mycoolnewbusiness.com'
    Again, you should replace https://colexample.com with the actual old domain name and https://mycoolnewbusiness.com with the actual new domain name.

You'll see a success message confirming that the data has been replaced and a table with the number of changes for each database item.

More info

Share this article