Skip to content

Search and replace

WordPress stores full addresses, such as https://old.example.com/wp-content/uploads/…, all through its database. When an address changes, those need replacing everywhere, including inside serialized plugin settings, which a plain SQL replace would break. WP-CLI’s search-replace handles this correctly.

You don’t need to run a search and replace yourself when you:

  • take a website live from its preview address, or connect your domain to it;
  • create a staging copy, refresh staging or push staging live with the database;
  • clone a website to a new domain.

In each case Netkeel replaces the old address with the new one in the copied database.

Use the WP-CLI terminal for anything else, such as moving from http:// to https:// or replacing an old domain left behind by a migration.

  1. Take a backup. Click Create backup on the website’s overview, and wait for it to finish. A search and replace can’t be undone otherwise.

  2. Do a dry run. Open WordPress › WP-CLI terminal and run:

    search-replace 'https://old.example.com' 'https://example.com' --dry-run

    Nothing changes. WP-CLI lists each table and how many replacements it would make.

  3. Check the numbers. If they look wrong, adjust the search text and run the dry run again.

  4. Run it for real. Run the same command without --dry-run.

  5. Clear the cache. Click Purge cache so visitors get the updated pages.

  • --dry-run: show what would change, without changing anything.
  • --skip-columns=guid: leave post GUIDs alone. WordPress uses them as permanent IDs for feeds.
  • --precise: slower, but catches values the fast mode might miss.
  • --report-changed-only: list only the tables where something changed.
  • Team members who have access to only some websites can run search-replace only with --dry-run. Ask the workspace owner to run the real one.
  • On a very large database, run it during a quiet time, or run it over SSH (see Hosting › SSH / SFTP) where you can watch it work.
  • Try it on a staging copy first if the change is big or you aren’t sure of the result.