Running a Search and Replace in Your WordPress Database

Running a Search and Replace in Your WordPress Database

WordPress stores URLs and text in many database tables. After a domain change, SSL migration, or copying staging to production, old URLs or text can remain in the database and cause broken links, mixed content warnings, or incorrect redirects.

Always take a backup before running a search-replace. KPanel creates a pre-update backup automatically when you use the built-in Search & Replace action, but if you are running WP-CLI commands manually, create a backup first from the Backups tab.


When You Need Search and Replace

  • Migrating from http:// to https:// (SSL setup)
  • Changing your domain (e.g. old-domain.com to new-domain.com)
  • After pushing staging to production (staging URL left in the database)
  • Updating a URL used across many posts (e.g. old image CDN URL)

Method 1: KPanel Search & Replace (built-in)

KPanel runs WP-CLI search-replace through the WordPress Quick Actions panel.

  1. Go to your site in KPanel
  2. Click WordPress in the top navigation
  3. On the Quick Actions tab, find the Search & Replace card
  4. Click Configure
  5. Enter the text to find in the Find (old value) field
  6. Enter the replacement in the Replace with field
  7. Click Run
  8. Confirm the dialog (a backup is created automatically first)

This runs wp search-replace across all tables using WP-CLI.


Method 2: WP-CLI via the Console (more control)

Use the Console tab for more control, including a dry run to preview changes first.

  1. Go to your site in KPanel
  2. Click WordPress in the top navigation
  3. Click the Console tab

Dry run first (no changes made):

search-replace 'http://old-domain.com' 'https://new-domain.com' --all-tables --dry-run

This shows how many replacements would be made in each table without making any changes. Review the output before proceeding.

Run the actual replacement:

search-replace 'http://old-domain.com' 'https://new-domain.com' --all-tables

Note: in the Console tab you type commands without the wp prefix -- KPanel adds it automatically.

Common flags:

FlagWhat it does
--all-tablesSearches all tables including custom plugin tables, not just core WP tables
--dry-runPreviews changes without writing anything to the database
--preciseUses PHP for serialisation handling instead of SQL (slower but handles edge cases)

Method 3: phpMyAdmin (manual)

Use this only if WP-CLI is unavailable. You will need to update multiple tables manually.

Key tables that hold URLs:

TableColumns
wp_optionsoption_value (rows: siteurl, home)
wp_postspost_content, guid
wp_postmetameta_value
  1. Open phpMyAdmin (KPanel: Files menu, then Database)
  2. Click the SQL tab
  3. Run a query for each table:
UPDATE wp_options
SET option_value = REPLACE(option_value, 'http://old-domain.com', 'https://new-domain.com')
WHERE option_name IN ('siteurl', 'home');

UPDATE wp_posts
SET post_content = REPLACE(post_content, 'http://old-domain.com', 'https://new-domain.com');

UPDATE wp_posts
SET guid = REPLACE(guid, 'http://old-domain.com', 'https://new-domain.com');

UPDATE wp_postmeta
SET meta_value = REPLACE(meta_value, 'http://old-domain.com', 'https://new-domain.com');

Warning: phpMyAdmin's REPLACE() function does not handle PHP serialised data correctly. Serialised strings (used by many plugins) store string lengths, and a manual SQL replace will corrupt those entries. Use WP-CLI where possible, as it handles serialised data correctly.


After Running Search and Replace

  1. Clear your WordPress cache: WordPress tab, then Flush Cache
  2. Visit your site and check for mixed content warnings (the browser padlock)
  3. Check your site's admin area: Settings, then Permalinks, then click Save Changes (re-flushes rewrite rules)
  4. If using a caching plugin, clear its cache from the plugin settings
Was this article helpful?

Still need help?

Our support team is here on business days, NZT.

Back to Help Centre