Changing values across many rows.
WHEN YOU NEED IT
After a domain change After moving from http to https After a migration where URLs changed
THE DANGER
Serialised data. Applications store some settings as text containing the length of each string.
A plain SQL replace changes the text without updating the recorded lengths, which corrupts the value silently.
Widget settings, theme options and plugin configuration are commonly stored this way.
THE SYMPTOM
Widgets disappearing, settings reverting, or a plugin behaving as though unconfigured, after a replace that appeared to work.
THE CORRECT TOOLS
A search-replace plugin that handles serialisation WP-CLI, which handles it correctly A dedicated search-replace script
Any of these. Not a plain SQL query.
THE PROCEDURE
- Back up the database.
- Run the replace with a tool that understands serialisation.
- Search afterwards for any remaining instances.
- Clear caches and test.
WHAT TO REPLACE
The full old URL including scheme, to the full new one.