PHPackages                             wp-cli/search-replace-command - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. wp-cli/search-replace-command

ActiveWp-cli-package[Database &amp; ORM](/categories/database)

wp-cli/search-replace-command
=============================

Searches/replaces strings in the database.

v2.1.11(2mo ago)597.5M↑24.9%44[12 issues](https://github.com/wp-cli/search-replace-command/issues)[2 PRs](https://github.com/wp-cli/search-replace-command/pulls)8MITGherkinCI passing

Since Mar 13Pushed 1mo ago9 watchersCompare

[ Source](https://github.com/wp-cli/search-replace-command)[ Packagist](https://packagist.org/packages/wp-cli/search-replace-command)[ Docs](https://github.com/wp-cli/search-replace-command)[ RSS](/packages/wp-cli-search-replace-command/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (10)Versions (55)Used By (8)

wp-cli/search-replace-command
=============================

[](#wp-clisearch-replace-command)

Searches/replaces strings in the database.

[![Testing](https://github.com/wp-cli/search-replace-command/actions/workflows/testing.yml/badge.svg)](https://github.com/wp-cli/search-replace-command/actions/workflows/testing.yml) [![Code Coverage](https://camo.githubusercontent.com/b44d1858b72612a173c22e32e889467a523c8f394abc90287080d3e5be2d573f/68747470733a2f2f636f6465636f762e696f2f67682f77702d636c692f7365617263682d7265706c6163652d636f6d6d616e642f6272616e63682f6d61696e2f67726170682f62616467652e737667)](https://codecov.io/gh/wp-cli/search-replace-command/tree/main)

Quick links: [Using](#using) | [Installing](#installing) | [Contributing](#contributing) | [Support](#support)

Using
-----

[](#using)

```
wp search-replace [] [] [...] [--old=] [--new=] [--dry-run] [--network] [--all-tables-with-prefix] [--all-tables] [--export[=]] [--export_insert_size=] [--skip-tables=] [--skip-columns=] [--include-columns=] [--precise] [--recurse-objects] [--verbose] [--regex] [--regex-flags=] [--regex-delimiter=] [--regex-limit=] [--format=] [--report] [--report-changed-only] [--log[=]] [--before_context=] [--after_context=]

```

Searches through all rows in a selection of tables and replaces appearances of the first string with the second string.

By default, the command uses tables registered to the `$wpdb` object. On multisite, this will just be the tables for the current site unless `--network` is specified.

Search/replace intelligently handles PHP serialized data, and does not change primary key values.

Tables without a primary key are skipped. To check whether a table has a primary key, run `wp db query 'DESCRIBE '` and look for 'PRI' in the Key column.

**OPTIONS**

```
[]
	A string to search for within the database.

[]
	Replace instances of the first string with this new string.

[...]
	List of database tables to restrict the replacement to. Wildcards are
	supported, e.g. `'wp_*options'` or `'wp_post*'`.

[--old=]
	An alternative way to specify the search string. Use this when the
	search string starts with '--' (e.g., --old='--some-text').

[--new=]
	An alternative way to specify the replacement string. Use this when the
	replacement string starts with '--' (e.g., --new='--other-text').

[--dry-run]
	Run the entire search/replace operation and show report, but don't save
	changes to the database.

[--network]
	Search/replace through all the tables registered to $wpdb in a
	multisite install.

[--all-tables-with-prefix]
	Enable replacement on any tables that match the table prefix even if
	not registered on $wpdb.

[--all-tables]
	Enable replacement on ALL tables in the database, regardless of the
	prefix, and even if not registered on $wpdb. Overrides --network
	and --all-tables-with-prefix.

[--export[=]]
	Write transformed data as SQL file instead of saving replacements to
	the database. If  is not supplied, will output to STDOUT.

[--export_insert_size=]
	Define number of rows in single INSERT statement when doing SQL export.
	You might want to change this depending on your database configuration
	(e.g. if you need to do fewer queries). Default: 50

[--skip-tables=]
	Do not perform the replacement on specific tables. Use commas to
	specify multiple tables. Wildcards are supported, e.g. `'wp_*options'` or `'wp_post*'`.

[--skip-columns=]
	Do not perform the replacement on specific columns. Use commas to
	specify multiple columns. Table-qualified column names ("table.column")
	are supported to apply the skip to a specific table only.

[--include-columns=]
	Perform the replacement on specific columns. Use commas to
	specify multiple columns. Table-qualified column names ("table.column")
	are supported to apply the inclusion to a specific table only.

[--precise]
	Force the use of PHP (instead of SQL) for all columns. By default, the command
	uses fast SQL queries, but automatically switches to PHP for columns containing
	serialized data. Use this flag to ensure PHP processes all columns, which is
	slower but handles complex serialized data structures more reliably.

[--recurse-objects]
	Enable recursing into objects to replace strings. Defaults to true;
	pass --no-recurse-objects to disable.

[--verbose]
	Prints rows to the console as they're updated.

[--regex]
	Runs the search using a regular expression (without delimiters).
	Warning: search-replace will take about 15-20x longer when using --regex.

[--regex-flags=]
	Pass PCRE modifiers to regex search-replace (e.g. 'i' for case-insensitivity).

[--regex-delimiter=]
	The delimiter to use for the regex. It must be escaped if it appears in the search string. The default value is the result of `chr(1)`.

[--regex-limit=]
	The maximum possible replacements for the regex per row (or per unserialized data bit per row). Defaults to -1 (no limit).

[--format=]
	Render output in a particular format.
	---
	default: table
	options:
	  - table
	  - count
	---

[--report]
	Produce report. Defaults to true.

[--report-changed-only]
	Report changed fields only. Defaults to false, unless logging, when it defaults to true.

[--log[=]]
	Log the items changed. If  is not supplied or is "-", will output to STDOUT.
	Warning: causes a significant slow down, similar or worse to enabling --precise or --regex.

[--before_context=]
	For logging, number of characters to display before the old match and the new replacement. Default 40. Ignored if not logging.

[--after_context=]
	For logging, number of characters to display after the old match and the new replacement. Default 40. Ignored if not logging.

```

**EXAMPLES**

```
# Search and replace but skip one column
$ wp search-replace 'http://example.test' 'http://example.com' --skip-columns=guid

# Run search/replace operation but dont save in database
$ wp search-replace 'foo' 'bar' wp_posts wp_postmeta wp_terms --dry-run

# Run case-insensitive regex search/replace operation (slow)
$ wp search-replace '\[foo id="([0-9]+)"' '[bar id="\1"' --regex --regex-flags='i'

# Turn your production multisite database into a local dev database
$ wp search-replace --url=example.com example.com example.test 'wp_*options' wp_blogs wp_site --network

# Search/replace to a SQL file without transforming the database
$ wp search-replace foo bar --export=database.sql

# Search/replace string containing hyphens
$ wp search-replace --old='--old-string' --new='new-string'

# Use precise mode for complex serialized data
$ wp search-replace 'oldurl.com' 'newurl.com' --precise

# Bash script: Search/replace production to development url (multisite compatible)
#!/bin/bash
if $(wp --url=http://example.com core is-installed --network); then
    wp search-replace --url=http://example.com 'http://example.com' 'http://example.test' --recurse-objects --network --skip-columns=guid --skip-tables=wp_users
else
    wp search-replace 'http://example.com' 'http://example.test' --recurse-objects --skip-columns=guid --skip-tables=wp_users
fi

```

Installing
----------

[](#installing)

This package is included with WP-CLI itself, no additional installation necessary.

To install the latest version of this package over what's included in WP-CLI, run:

```
wp package install git@github.com:wp-cli/search-replace-command.git

```

Contributing
------------

[](#contributing)

We appreciate you taking the initiative to contribute to this project.

Contributing isn’t limited to just code. We encourage you to contribute in the way that best fits your abilities, by writing tutorials, giving a demo at your local meetup, helping other users with their support questions, or revising our documentation.

For a more thorough introduction, [check out WP-CLI's guide to contributing](https://make.wordpress.org/cli/handbook/contributing/). This package follows those policy and guidelines.

### Reporting a bug

[](#reporting-a-bug)

Think you’ve found a bug? We’d love for you to help us get it fixed.

Before you create a new issue, you should [search existing issues](https://github.com/wp-cli/search-replace-command/issues?q=label%3Abug%20) to see if there’s an existing resolution to it, or if it’s already been fixed in a newer version.

Once you’ve done a bit of searching and discovered there isn’t an open or fixed issue for your bug, please [create a new issue](https://github.com/wp-cli/search-replace-command/issues/new). Include as much detail as you can, and clear steps to reproduce if possible. For more guidance, [review our bug report documentation](https://make.wordpress.org/cli/handbook/bug-reports/).

### Creating a pull request

[](#creating-a-pull-request)

Want to contribute a new feature? Please first [open a new issue](https://github.com/wp-cli/search-replace-command/issues/new) to discuss whether the feature is a good fit for the project.

Once you've decided to commit the time to seeing your pull request through, [please follow our guidelines for creating a pull request](https://make.wordpress.org/cli/handbook/pull-requests/) to make sure it's a pleasant experience. See "[Setting up](https://make.wordpress.org/cli/handbook/pull-requests/#setting-up)" for details specific to working on this package locally.

### License

[](#license)

This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.

Support
-------

[](#support)

GitHub issues aren't for general support questions, but there are other venues you can try:

*This README.md is generated dynamically from the project's codebase using `wp scaffold package-readme` ([doc](https://github.com/wp-cli/scaffold-package-command#wp-scaffold-package-readme)). To suggest changes, please submit a pull request against the corresponding part of the codebase.*

###  Health Score

68

—

FairBetter than 100% of packages

Maintenance85

Actively maintained with recent releases

Popularity60

Solid adoption and visibility

Community38

Small or concentrated contributor base

Maturity77

Established project with proven stability

 Bus Factor2

2 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~73 days

Recently: every ~157 days

Total

46

Last Release

62d ago

Major Versions

v1.3.1 → v2.0.02018-08-05

### Community

Maintainers

![](https://www.gravatar.com/avatar/4b5740d002b5556abcceed36e016c8f8ba6f533eefef6107b3c60a830704993b?d=identicon)[danielbachhuber](/maintainers/danielbachhuber)

![](https://www.gravatar.com/avatar/6dde7f578e5530884238e7173f768ae3a890b6d66eb99262a82f2c494a1b67d4?d=identicon)[schlessera](/maintainers/schlessera)

---

Top Contributors

[![danielbachhuber](https://avatars.githubusercontent.com/u/36432?v=4)](https://github.com/danielbachhuber "danielbachhuber (638 commits)")[![scribu](https://avatars.githubusercontent.com/u/225715?v=4)](https://github.com/scribu "scribu (182 commits)")[![schlessera](https://avatars.githubusercontent.com/u/83631?v=4)](https://github.com/schlessera "schlessera (176 commits)")[![swissspidy](https://avatars.githubusercontent.com/u/841956?v=4)](https://github.com/swissspidy "swissspidy (50 commits)")[![miya0001](https://avatars.githubusercontent.com/u/309946?v=4)](https://github.com/miya0001 "miya0001 (45 commits)")[![lkwdwrd](https://avatars.githubusercontent.com/u/1895738?v=4)](https://github.com/lkwdwrd "lkwdwrd (29 commits)")[![gitlost](https://avatars.githubusercontent.com/u/481982?v=4)](https://github.com/gitlost "gitlost (23 commits)")[![villevuor](https://avatars.githubusercontent.com/u/1097009?v=4)](https://github.com/villevuor "villevuor (22 commits)")[![Copilot](https://avatars.githubusercontent.com/in/1143301?v=4)](https://github.com/Copilot "Copilot (14 commits)")[![marksabbath](https://avatars.githubusercontent.com/u/4185923?v=4)](https://github.com/marksabbath "marksabbath (14 commits)")[![MarkBerube](https://avatars.githubusercontent.com/u/10816162?v=4)](https://github.com/MarkBerube "MarkBerube (13 commits)")[![jrfnl](https://avatars.githubusercontent.com/u/663378?v=4)](https://github.com/jrfnl "jrfnl (13 commits)")[![JPry](https://avatars.githubusercontent.com/u/871924?v=4)](https://github.com/JPry "JPry (11 commits)")[![ernilambar](https://avatars.githubusercontent.com/u/2098823?v=4)](https://github.com/ernilambar "ernilambar (10 commits)")[![cyberhobo](https://avatars.githubusercontent.com/u/286838?v=4)](https://github.com/cyberhobo "cyberhobo (9 commits)")[![szepeviktor](https://avatars.githubusercontent.com/u/952007?v=4)](https://github.com/szepeviktor "szepeviktor (8 commits)")[![NateWr](https://avatars.githubusercontent.com/u/2306629?v=4)](https://github.com/NateWr "NateWr (8 commits)")[![mwilliamson](https://avatars.githubusercontent.com/u/391876?v=4)](https://github.com/mwilliamson "mwilliamson (6 commits)")[![mullnerz](https://avatars.githubusercontent.com/u/197506?v=4)](https://github.com/mullnerz "mullnerz (6 commits)")[![Sidsector9](https://avatars.githubusercontent.com/u/17757960?v=4)](https://github.com/Sidsector9 "Sidsector9 (5 commits)")

---

Tags

clidatabasedbgrephacktoberfestreplacesearchwordpresswp-cliwp-cli-package

### Embed Badge

![Health badge](/badges/wp-cli-search-replace-command/health.svg)

```
[![Health](https://phpackages.com/badges/wp-cli-search-replace-command/health.svg)](https://phpackages.com/packages/wp-cli-search-replace-command)
```

###  Alternatives

[doctrine/orm

Object-Relational-Mapper for PHP

10.2k285.3M6.2k](/packages/doctrine-orm)[jdorn/sql-formatter

a PHP SQL highlighting library

3.9k115.1M102](/packages/jdorn-sql-formatter)[illuminate/database

The Illuminate Database package.

2.8k52.4M9.4k](/packages/illuminate-database)[reliese/laravel

Reliese Components for Laravel Framework code generation.

1.7k3.4M16](/packages/reliese-laravel)[wildside/userstamps

Laravel Userstamps provides an Eloquent trait which automatically maintains `created\_by` and `updated\_by` columns on your model, populated by the currently authenticated user in your application.

7511.7M13](/packages/wildside-userstamps)[usmanhalalit/laracsv

A Laravel package to easily generate CSV files from Eloquent model.

6151.7M4](/packages/usmanhalalit-laracsv)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
