In a WordPress installation, a certain number of database tables are registered in the $wpdb
object. To see what they are, you can run the WP-CLI command wp db tables
.
On my local WP installation, these are the $wpdb
-registered tables:
wp_users
wp_usermeta
wp_posts
wp_comments
wp_links
wp_options
wp_postmeta
wp_terms
wp_term_taxonomy
wp_term_relationships
wp_termmeta
wp_commentmeta
wp_blogs
wp_signups
wp_site
wp_sitemeta
wp_sitecategories
wp_registration_log
wp_blog_versions
The WordPress table prefix, by default, is wp_
. You can change this in your wp-config.php
file, and might choose to do this for any number of reasons: maybe you need to run multiple WordPress installations from a single database, or perhaps you want to harden your WordPress installation by making certain things harder for an attacker to guess.
Plugins and/or themes might create new tables in the WordPress database: for example, Gravity Forms generates a bunch of tables in the format {$wpdb->prefix}_rg_{table_name}
(so, in the default WordPress installation, wp_rg_{table_name}
). When you run wp search-replace {search} {replace}
, these other tables will not be searched, because the $wpdb
object doesn't know about them.
To search these non-$wpdb
-registered tables that still have the WordPress table prefix (ie, wp_
or whatever you've set it to), you use the --all-tables-with-prefix
flag on the wp search-replace
invocation.
If you want to search all the tables in your database, regardless of their prefix, you can use the --all-tables
flag. Be careful, though, as this may have unintended consequences (in a Multisite environment, for example, or in the case where you have multiple WordPress installations running from a single database).
As an aside, I strongly recommend using the --dry-run
flag for each search & replace that you do, so you can see what will be affected before you make changes to your database.
References