wp db search
Finds a string in the database.
Searches through all of the text columns in a selection of database tables for a given string, Outputs colorized references to the string.
Defaults to searching through all tables registered to $wpdb. On multisite, this default is limited to the tables for the current site.
^
and $
tokens to mark the start and end of a match, respectively.chr(1)
.The percent color codes available are:
Code | Color |
---|---|
%y | Yellow (dark) (mustard) |
%g | Green (dark) |
%b | Blue (dark) |
%r | Red (dark) |
%m | Magenta (dark) |
%c | Cyan (dark) |
%w | White (dark) (light gray) |
%k | Black |
%Y | Yellow (bright) |
%G | Green (bright) |
%B | Blue (bright) |
%R | Red (bright) |
%M | Magenta (bright) |
%C | Cyan (bright) |
%W | White |
%K | Black (bright) (dark gray) |
%3 | Yellow background (dark) (mustard) |
%2 | Green background (dark) |
%4 | Blue background (dark) |
%1 | Red background (dark) |
%5 | Magenta background (dark) |
%6 | Cyan background (dark) |
%7 | White background (dark) (light gray) |
%0 | Black background |
%8 | Reverse |
%U | Underline |
%F | Blink (unlikely to work) |
They can be concatenated. For instance, the default match color of black on a mustard (dark yellow) background %3%k
can be made black on a bright yellow background with %Y%0%8
.
# Search through the database for the 'wordpress-develop' string
$ wp db search wordpress-develop
wp_options:option_value
1:http://wordpress-develop.dev
wp_options:option_value
1:https://example.com/foo
...
# Search through a multisite database on the subsite 'foo' for the 'example.com' string
$ wp db search example.com --url=example.com/foo
wp_2_comments:comment_author_url
1:https://example.com/
wp_2_options:option_value
...
# Search through the database for the 'https?://' regular expression, printing stats.
$ wp db search 'https?://' --regex --stats
wp_comments:comment_author_url
1:https://wordpress.org/
...
Success: Found 99146 matches in 10.752s (10.559s searching). Searched 12 tables, 53 columns, 1358907 rows. 1 table skipped: wp_term_relationships.
# SQL search database table 'wp_options' where 'option_name' match 'foo'
wp db query 'SELECT * FROM wp_options WHERE option_name like "%foo%"' --skip-column-names
+----+--------------+--------------------------------+-----+
| 98 | foo_options | a:1:{s:12:"_multiwidget";i:1;} | yes |
| 99 | foo_settings | a:0:{} | yes |
+----+--------------+--------------------------------+-----+
# SQL search and delete records from database table 'wp_options' where 'option_name' match 'foo'
wp db query "DELETE from wp_options where option_id in ($(wp db query "SELECT GROUP_CONCAT(option_id SEPARATOR ',') from wp_options where option_name like '%foo%';" --silent --skip-column-names))"
These global parameters have the same behavior across all commands and affect how WP-CLI interacts with WordPress.
Argument | Description |
---|---|
--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=[<scheme>:][<user>@]<host\|container>[:<port>][<path>] |
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=<id\|login\|email> |
Set the WordPress user. |
--skip-plugins[=<plugins>] |
Skip loading all plugins, or a comma-separated list of plugins. Note: mu-plugins are still loaded. |
--skip-themes[=<themes>] |
Skip loading all themes, or a comma-separated list of themes. |
--skip-packages |
Skip 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). |
--context=<context> |
Load WordPress in a given context. |
--[no-]color |
Whether to colorize the output. |
--debug[=<group>] |
Show all PHP errors and add verbosity to WP-CLI output. Built-in groups include: bootstrap, commandfactory, and help. |
--prompt[=<assoc>] |
Prompt the user to enter values for all command arguments, or a subset specified as comma-separated values. |
--quiet |
Suppress informational messages. |