Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions src/wp-includes/class-wp-meta-query.php
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ public function parse_query_vars( $qv ) {
* the rest of the meta_query).
*/
$primary_meta_query = array();
foreach ( array( 'key', 'compare', 'type', 'compare_key', 'type_key' ) as $key ) {
foreach ( array( 'key', 'compare', 'type', 'compare_key', 'type_key', 'like_escape' ) as $key ) {
if ( ! empty( $qv[ "meta_$key" ] ) ) {
$primary_meta_query[ $key ] = $qv[ "meta_$key" ];
}
Expand Down Expand Up @@ -619,9 +619,10 @@ public function get_sql_for_clause( &$clause, $parent_query, $clause_key = '' )
$clause['alias'] = $alias;

// Determine the data type.
$_meta_type = $clause['type'] ?? '';
$meta_type = $this->get_cast_for_type( $_meta_type );
$clause['cast'] = $meta_type;
$_meta_type = $clause['type'] ?? '';
$meta_type = $this->get_cast_for_type( $_meta_type );
$clause['cast'] = $meta_type;
$meta_like_escape = isset( $clause['like_escape'] ) ? (bool) $clause['like_escape'] : false;

// Fallback for clause keys is the table alias. Key must be a string.
if ( is_int( $clause_key ) || ! $clause_key ) {
Expand Down Expand Up @@ -752,8 +753,10 @@ public function get_sql_for_clause( &$clause, $parent_query, $clause_key = '' )

case 'LIKE':
case 'NOT LIKE':
$meta_value = '%' . $wpdb->esc_like( $meta_value ) . '%';
$where = $wpdb->prepare( '%s', $meta_value );
if ( ! $meta_like_escape ) {
$meta_value = '%' . $wpdb->esc_like( $meta_value ) . '%';
}
$where = $wpdb->prepare( '%s', $meta_value );
break;

// EXISTS with a value is interpreted as '='.
Expand Down
Loading