{"id":15041116,"url":"https://github.com/wp-cli/search-replace-command","last_synced_at":"2025-05-15T14:07:38.424Z","repository":{"id":18654045,"uuid":"84850883","full_name":"wp-cli/search-replace-command","owner":"wp-cli","description":"Searches/replaces strings in the database.","archived":false,"fork":false,"pushed_at":"2025-05-12T18:30:34.000Z","size":8854,"stargazers_count":58,"open_issues_count":19,"forks_count":45,"subscribers_count":13,"default_branch":"main","last_synced_at":"2025-05-12T19:48:08.533Z","etag":null,"topics":["cli","database","db","grep","hacktoberfest","replace","search","wordpress","wp-cli","wp-cli-package"],"latest_commit_sha":null,"homepage":null,"language":"Gherkin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/wp-cli.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2017-03-13T16:42:48.000Z","updated_at":"2025-05-12T18:30:37.000Z","dependencies_parsed_at":"2024-01-09T02:37:45.812Z","dependency_job_id":"b402cb14-0a03-4d10-b8a7-442e74208f3e","html_url":"https://github.com/wp-cli/search-replace-command","commit_stats":{"total_commits":750,"total_committers":76,"mean_commits":9.868421052631579,"dds":0.7893333333333333,"last_synced_commit":"2440cfba3b3dd3800644e6c1fcb04b642a45f094"},"previous_names":[],"tags_count":43,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wp-cli%2Fsearch-replace-command","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wp-cli%2Fsearch-replace-command/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wp-cli%2Fsearch-replace-command/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wp-cli%2Fsearch-replace-command/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wp-cli","download_url":"https://codeload.github.com/wp-cli/search-replace-command/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254355335,"owners_count":22057354,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cli","database","db","grep","hacktoberfest","replace","search","wordpress","wp-cli","wp-cli-package"],"created_at":"2024-09-24T20:45:36.850Z","updated_at":"2025-05-15T14:07:33.411Z","avatar_url":"https://github.com/wp-cli.png","language":"Gherkin","readme":"wp-cli/search-replace-command\n=============================\n\nSearches/replaces strings in the database.\n\n[![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)\n\nQuick links: [Using](#using) | [Installing](#installing) | [Contributing](#contributing) | [Support](#support)\n\n## Using\n\n~~~\nwp search-replace \u003cold\u003e \u003cnew\u003e [\u003ctable\u003e...] [--dry-run] [--network] [--all-tables-with-prefix] [--all-tables] [--export[=\u003cfile\u003e]] [--export_insert_size=\u003crows\u003e] [--skip-tables=\u003ctables\u003e] [--skip-columns=\u003ccolumns\u003e] [--include-columns=\u003ccolumns\u003e] [--precise] [--recurse-objects] [--verbose] [--regex] [--regex-flags=\u003cregex-flags\u003e] [--regex-delimiter=\u003cregex-delimiter\u003e] [--regex-limit=\u003cregex-limit\u003e] [--format=\u003cformat\u003e] [--report] [--report-changed-only] [--log[=\u003cfile\u003e]] [--before_context=\u003cnum\u003e] [--after_context=\u003cnum\u003e]\n~~~\n\nSearches through all rows in a selection of tables and replaces\nappearances of the first string with the second string.\n\nBy default, the command uses tables registered to the `$wpdb` object. On\nmultisite, this will just be the tables for the current site unless\n`--network` is specified.\n\nSearch/replace intelligently handles PHP serialized data, and does not\nchange primary key values.\n\n**OPTIONS**\n\n\t\u003cold\u003e\n\t\tA string to search for within the database.\n\n\t\u003cnew\u003e\n\t\tReplace instances of the first string with this new string.\n\n\t[\u003ctable\u003e...]\n\t\tList of database tables to restrict the replacement to. Wildcards are\n\t\tsupported, e.g. `'wp_*options'` or `'wp_post*'`.\n\n\t[--dry-run]\n\t\tRun the entire search/replace operation and show report, but don't save\n\t\tchanges to the database.\n\n\t[--network]\n\t\tSearch/replace through all the tables registered to $wpdb in a\n\t\tmultisite install.\n\n\t[--all-tables-with-prefix]\n\t\tEnable replacement on any tables that match the table prefix even if\n\t\tnot registered on $wpdb.\n\n\t[--all-tables]\n\t\tEnable replacement on ALL tables in the database, regardless of the\n\t\tprefix, and even if not registered on $wpdb. Overrides --network\n\t\tand --all-tables-with-prefix.\n\n\t[--export[=\u003cfile\u003e]]\n\t\tWrite transformed data as SQL file instead of saving replacements to\n\t\tthe database. If \u003cfile\u003e is not supplied, will output to STDOUT.\n\n\t[--export_insert_size=\u003crows\u003e]\n\t\tDefine number of rows in single INSERT statement when doing SQL export.\n\t\tYou might want to change this depending on your database configuration\n\t\t(e.g. if you need to do fewer queries). Default: 50\n\n\t[--skip-tables=\u003ctables\u003e]\n\t\tDo not perform the replacement on specific tables. Use commas to\n\t\tspecify multiple tables. Wildcards are supported, e.g. `'wp_*options'` or `'wp_post*'`.\n\n\t[--skip-columns=\u003ccolumns\u003e]\n\t\tDo not perform the replacement on specific columns. Use commas to\n\t\tspecify multiple columns.\n\n\t[--include-columns=\u003ccolumns\u003e]\n\t\tPerform the replacement on specific columns. Use commas to\n\t\tspecify multiple columns.\n\n\t[--precise]\n\t\tForce the use of PHP (instead of SQL) which is more thorough,\n\t\tbut slower.\n\n\t[--recurse-objects]\n\t\tEnable recursing into objects to replace strings. Defaults to true;\n\t\tpass --no-recurse-objects to disable.\n\n\t[--verbose]\n\t\tPrints rows to the console as they're updated.\n\n\t[--regex]\n\t\tRuns the search using a regular expression (without delimiters).\n\t\tWarning: search-replace will take about 15-20x longer when using --regex.\n\n\t[--regex-flags=\u003cregex-flags\u003e]\n\t\tPass PCRE modifiers to regex search-replace (e.g. 'i' for case-insensitivity).\n\n\t[--regex-delimiter=\u003cregex-delimiter\u003e]\n\t\tThe 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)`.\n\n\t[--regex-limit=\u003cregex-limit\u003e]\n\t\tThe maximum possible replacements for the regex per row (or per unserialized data bit per row). Defaults to -1 (no limit).\n\n\t[--format=\u003cformat\u003e]\n\t\tRender output in a particular format.\n\t\t---\n\t\tdefault: table\n\t\toptions:\n\t\t  - table\n\t\t  - count\n\t\t---\n\n\t[--report]\n\t\tProduce report. Defaults to true.\n\n\t[--report-changed-only]\n\t\tReport changed fields only. Defaults to false, unless logging, when it defaults to true.\n\n\t[--log[=\u003cfile\u003e]]\n\t\tLog the items changed. If \u003cfile\u003e is not supplied or is \"-\", will output to STDOUT.\n\t\tWarning: causes a significant slow down, similar or worse to enabling --precise or --regex.\n\n\t[--before_context=\u003cnum\u003e]\n\t\tFor logging, number of characters to display before the old match and the new replacement. Default 40. Ignored if not logging.\n\n\t[--after_context=\u003cnum\u003e]\n\t\tFor logging, number of characters to display after the old match and the new replacement. Default 40. Ignored if not logging.\n\n**EXAMPLES**\n\n    # Search and replace but skip one column\n    $ wp search-replace 'http://example.test' 'http://example.com' --skip-columns=guid\n\n    # Run search/replace operation but dont save in database\n    $ wp search-replace 'foo' 'bar' wp_posts wp_postmeta wp_terms --dry-run\n\n    # Run case-insensitive regex search/replace operation (slow)\n    $ wp search-replace '\\[foo id=\"([0-9]+)\"' '[bar id=\"\\1\"' --regex --regex-flags='i'\n\n    # Turn your production multisite database into a local dev database\n    $ wp search-replace --url=example.com example.com example.test 'wp_*options' wp_blogs wp_site --network\n\n    # Search/replace to a SQL file without transforming the database\n    $ wp search-replace foo bar --export=database.sql\n\n    # Bash script: Search/replace production to development url (multisite compatible)\n    #!/bin/bash\n    if $(wp --url=http://example.com core is-installed --network); then\n        wp search-replace --url=http://example.com 'http://example.com' 'http://example.test' --recurse-objects --network --skip-columns=guid --skip-tables=wp_users\n    else\n        wp search-replace 'http://example.com' 'http://example.test' --recurse-objects --skip-columns=guid --skip-tables=wp_users\n    fi\n\n## Installing\n\nThis package is included with WP-CLI itself, no additional installation necessary.\n\nTo install the latest version of this package over what's included in WP-CLI, run:\n\n    wp package install git@github.com:wp-cli/search-replace-command.git\n\n## Contributing\n\nWe appreciate you taking the initiative to contribute to this project.\n\nContributing 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.\n\nFor 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.\n\n### Reporting a bug\n\nThink you’ve found a bug? We’d love for you to help us get it fixed.\n\nBefore 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.\n\nOnce 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/).\n\n### Creating a pull request\n\nWant 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.\n\nOnce 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.\n\n## Support\n\nGitHub issues aren't for general support questions, but there are other venues you can try: https://wp-cli.org/#support\n\n\n*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.*\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwp-cli%2Fsearch-replace-command","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwp-cli%2Fsearch-replace-command","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwp-cli%2Fsearch-replace-command/lists"}