This command will go through all rows in all tables and will replace all appearances of the old string with the new one.
-It will correctly handle serialized values.
+It will correctly handle serialized values, and will not change primary key values.
## OPTIONS
Show report, but don't perform the changes.
-* `--skip-guids`:
+* `--skip-columns=<columns>`:
- Do not perform the replacement in columns named 'guid'. Use to preserve existing GUID values when changing domain names.
+ Do not perform the replacement in the comma-separated columns. Useful to preserve existing guid column values when changing domain names.
## EXAMPLES
- wp search-replace 'http://example.dev' 'http://example.com' --dry-run
+ wp search-replace 'http://example.dev' 'http://example.com' --dry-run --skip-columns=guid
wp search-replace 'foo' 'bar' wp_posts wp_postmeta wp_terms
\fBwp\-search\-replace\fR \- Search/replace strings in the database\.
.
.SH "SYNOPSIS"
-wp search\-replace \fIold\fR \fInew\fR [\fItable\fR\.\.\.] [\-\-dry\-run] [\-\-skip\-guids]
+wp search\-replace \fIold\fR \fInew\fR [\fItable\fR\.\.\.] [\-\-dry\-run] [\-\-skip\-columns=\fIcolumns\fR]
.
.SH "DESCRIPTION"
This command will go through all rows in all tables and will replace all appearances of the old string with the new one\.
.
.P
-It will correctly handle serialized values\.
+It will correctly handle serialized values, and will not change primary key values\.
.
.SH "OPTIONS"
.
Show report, but don\'t perform the changes\.
.
.TP
-\fB\-\-skip\-guids\fR:
+\fB\-\-skip\-columns=<columns>\fR:
.
.IP
-Do not perform the replacement in columns named \'guid\'\. Use to preserve existing GUID values when changing domain names\.
+Do not perform the replacement in the comma\-separated columns\. Useful to preserve existing guid column values when changing domain names\.
.
.SH "EXAMPLES"
.
.nf
-wp search\-replace \'http://example\.dev\' \'http://example\.com\' \-\-dry\-run
+wp search\-replace \'http://example\.dev\' \'http://example\.com\' \-\-dry\-run \-\-skip\-columns=guid
wp search\-replace \'foo\' \'bar\' wp_posts wp_postmeta wp_terms
.
/**
* Search/replace strings in the database.
*
- * @synopsis <old> <new> [<table>...] [--dry-run] [--skip-guids]
+ * @synopsis <old> <new> [<table>...] [--dry-run] [--skip-columns=<columns>]
*/
public function __invoke( $args, $assoc_args ) {
global $wpdb;
$dry_run = isset( $assoc_args['dry-run'] );
- $skip_guids = isset( $assoc_args['skip-guids'] );
+ if ( isset( $assoc_args['skip-columns'] ) )
+ $skip_columns = explode( ',', $assoc_args['skip-columns'] );
+ else
+ $skip_columns = array();
foreach ( $tables as $table ) {
list( $primary_key, $columns ) = self::get_columns( $table );
foreach ( $columns as $col ) {
- if ( $skip_guids && 'guid' === $col )
+ if ( in_array( $col, $skip_columns ) )
continue;
$count = self::handle_col( $col, $primary_key, $table, $old, $new,