-
Notifications
You must be signed in to change notification settings - Fork 69
Implement exclude revision flag to remove revision results from the search #255
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 6 commits
a94e53e
aaaada6
2a9a529
c5e760d
38ee18a
95cfad1
c979679
6f2c866
efbd997
0505dcb
bcfccbe
0420e71
0ff712a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1264,6 +1264,9 @@ public function prefix() { | |
| * [--format=<format>] | ||
| * : Render output in a particular format. | ||
| * | ||
| * [--exclude_revisions] | ||
| * : Exclude revisions from the search. | ||
| * | ||
| * The percent color codes available are: | ||
| * | ||
| * | Code | Color | ||
|
|
@@ -1388,6 +1391,7 @@ public function search( $args, $assoc_args ) { | |
| $stats = Utils\get_flag_value( $assoc_args, 'stats', false ); | ||
| $fields = Utils\get_flag_value( $assoc_args, 'fields' ); | ||
| $format = Utils\get_flag_value( $assoc_args, 'format' ); | ||
| $exclude_revisions = Utils\get_flag_value( $assoc_args, 'exclude_revisions', false ); | ||
|
|
||
| $column_count = 0; | ||
| $row_count = 0; | ||
|
|
@@ -1452,10 +1456,19 @@ public function search( $args, $assoc_args ) { | |
| } | ||
|
|
||
| foreach ( $text_columns as $column ) { | ||
| $column_sql = self::esc_sql_ident( $column ); | ||
| $column_sql = self::esc_sql_ident( $column ); | ||
| $post_type_sql = self::esc_sql_ident( 'post_type' ); | ||
| if ( $regex ) { | ||
|
Comment on lines
1666
to
1669
|
||
| if ( $exclude_revisions && 'wp_posts' === $table ) { | ||
| // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- Escaped through esc_sql_ident/esc_like. | ||
| $results = $wpdb->get_results( "SELECT {$primary_key_sql}{$column_sql} FROM {$table_sql} WHERE {$post_type_sql} NOT IN ( 'revision' )" ); | ||
| } else { | ||
| // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- Escaped through esc_sql_ident/esc_like. | ||
| $results = $wpdb->get_results( "SELECT {$primary_key_sql}{$column_sql} FROM {$table_sql}" ); | ||
| } | ||
| } elseif ( $exclude_revisions && 'wp_posts' === $table ) { | ||
swissspidy marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
swissspidy marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
swissspidy marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- Escaped through esc_sql_ident/esc_like. | ||
| $results = $wpdb->get_results( "SELECT {$primary_key_sql}{$column_sql} FROM {$table_sql}" ); | ||
| $results = $wpdb->get_results( $wpdb->prepare( "SELECT {$primary_key_sql}{$column_sql} FROM {$table_sql} WHERE {$column_sql} LIKE %s AND {$post_type_sql} NOT IN ( 'revision' )", $esc_like_search ) ); | ||
|
Comment on lines
+1670
to
+1679
|
||
| } else { | ||
| // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- Escaped through esc_sql_ident/esc_like. | ||
| $results = $wpdb->get_results( $wpdb->prepare( "SELECT {$primary_key_sql}{$column_sql} FROM {$table_sql} WHERE {$column_sql} LIKE %s;", $esc_like_search ) ); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.