Support guide

WordPress Search and Replace: Moving URLs Safely

Why running a raw MySQL query to update URLs destroys custom themes, and how to properly migrate strings using serialized data handlers.

What this guide covers

Why running a raw MySQL query to update URLs destroys custom themes, and how to properly migrate strings using serialized data handlers.

When you move a WordPress site from a staging domain directly down to the live production domain, or finally upgrade from HTTP to HTTPS, you are required to update thousands of internal URLs.

A common, fatal mistake made by developers accustomed to older frameworks is logging into phpMyAdmin and attempting to run a basic string replacement command directly on the SQL database (UPDATE wp_posts SET post_content = replace...).

The Serialized Data Destruction

WordPress heavily utilizes Serialized Data. When complex theme settings or plugin configurations are saved, the database does not just record the raw text string. It records the text string and its exact character length constraint.

For example, it saves the string like this: s:14:"http://old.com".

If you use a basic raw SQL query to replace the 14-character string http://old.com with the 15-character string https://new.com, the character count is no longer mathematically accurate. The moment WordPress attempts to unpack that corrupted serialized array, it fundamentally rejects the data.

This single mistake is why moving a site using bad queries often results in all the widgets mysteriously vanishing, the homepage slider completely breaking, and the theme settings defaulting back to zero.

The Safe Method: WP-CLI or Dedicated Plugins

To migrate strings across a database securely, you must rely on tools inherently built to calculate, respect, and smoothly repack serialized array character counts.

Proactive WordPress support and monitoring
Proactive WordPress support and monitoring. Review the full technical context before changing a live site.
  1. WP-CLI: If you have direct terminal access to your VPS or dedicated server, the native WordPress Command Line Interface handles this elegantly. Running wp search-replace 'http://old.com' 'https://new.com' --all-tables dynamically scans the database, replaces the string, safely unpacks the array, recalculates the count, and safely repacks the data instantly without server timeouts.
  2. Plugin Alternative: If you do not have command-line root access, use an established industry plugin like Better Search Replace. It processes the serialized arrays properly right inside the visual WordPress dashboard.

Never allow raw SQL queries directly against the WordPress wp_options table unless you enjoy rebuilding themes from scratch.

Put the guidance into practice.

  1. 01
    Describe the symptom

    Record the affected URL, user, timing, expected result, and exact behavior without guessing the cause.

  2. 02
    Collect useful evidence

    Gather screenshots, logs, recent changes, environment details, and reproducible steps.

  3. 03
    Test the safest hypothesis

    Work from the highest-signal evidence and protect production before applying a fix.

  4. 04
    Verify the whole journey

    Confirm the reported issue, related workflows, monitoring, and customer-facing result.

Dev Circle technical support

Prefer to have the work handled?

Use us for one specific task or ongoing website care. Scope and pricing are confirmed before billable work starts.

Tell us what you need