wp search-replace <old> <new> <table>

Searches/replaces strings in the database

Arguments

NameDescription
oldA string to search for within the database
newReplace instances of the first string with this new string
tableList of database tables to restrict the replacement to. Wildcards are supported, e.g. 'wp_*options' or 'wp_post*'

Options

NameDescription
--dry-runRun the entire search/replace operation and show report, but don’t save changes to the database
--networkSearch/replace through all the tables registered to $wpdb in a multisite install
--all-tables-with-prefixEnable replacement on any tables that match the table prefix even if not registered on $wpdb
--all-tablesEnable 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 <file>Write transformed data as SQL file instead of saving replacements to the database. If <file> is not supplied, will output to STDOUT
--export_insert_size <rows>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 <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 <columns>Do not perform the replacement on specific columns. Use commas to specify multiple columns
--include-columns <columns>Perform the replacement on specific columns. Use commas to specify multiple columns
--preciseForce the use of PHP (instead of SQL) which is more thorough, but slower
--recurse-objectsEnable recursing into objects to replace strings. Defaults to true; pass –no-recurse-objects to disable
--no-recurse-objectsEnable recursing into objects to replace strings. Defaults to true; pass –no-recurse-objects to disable
--verbosePrints rows to the console as they’re updated
--regexRuns the search using a regular expression (without delimiters). Warning: search-replace will take about 15-20x longer when using –regex
--regex-flags <regex-flags>Pass PCRE modifiers to regex search-replace (e.g. ‘i’ for case-insensitivity)
--regex-delimiter <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 <regex-limit>The maximum possible replacements for the regex per row (or per unserialized data bit per row). Defaults to -1 (no limit)
--format <format>Render output in a particular format
--reportProduce report. Defaults to true
--report-changed-onlyReport changed fields only. Defaults to false, unless logging, when it defaults to true
--log [file]Log the items changed. If <file> 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 <num>For logging, number of characters to display before the old match and the new replacement. Default 40. Ignored if not logging
--after_context <num>For logging, number of characters to display after the old match and the new replacement. Default 40. Ignored if not logging
--path <path>Path to the WordPress files
--url <url>Pretend request came from given URL. In multisite, this argument is how the target site is specified
--ssh <options>Perform operation against a remote server over SSH (or a container using scheme of “docker”, “docker-compose”, “vagrant”)
--http <http>Perform operation against a remote WordPress installation over HTTP
--user <options>Set the WordPress user
--skip-pluginsSkip loading all plugins, or a comma-separated list of plugins. Note: mu-plugins are still loaded
--skip-plugins <plugins>Skip loading all plugins, or a comma-separated list of plugins. Note: mu-plugins are still loaded
--skip-themesSkip loading all themes, or a comma-separated list of themes
--skip-themes <themes>Skip loading all themes, or a comma-separated list of themes
--skip-packagesSkip loading all installed packages
--require <path>Load PHP file before running the command (may be used more than once)
--exec <php-code>Execute PHP code before running the command (may be used more than once)
--colorWhether to colorize the output
--no-colorWhether to colorize the output
--debugShow all PHP errors and add verbosity to WP-CLI output. Built-in groups include: bootstrap, commandfactory, and help
--debug <group>Show all PHP errors and add verbosity to WP-CLI output. Built-in groups include: bootstrap, commandfactory, and help
--promptPrompt the user to enter values for all command arguments, or a subset specified as comma-separated values
--prompt <assoc>Prompt the user to enter values for all command arguments, or a subset specified as comma-separated values
--quietSuppress informational messages