Make WordPress Core

Ticket #47286: wp_query patch

File wp_query patch, 1.8 KB (added by eddr, 7 years ago)

proposed solution idea

Line 
1--- C:/WinNMP/WWW/wpdev/wp-includes/class-wp-meta-query.php Mon Jun 17 00:53:04 2019
2+++ C:/WinNMP/WWW/wpdev/wp-includes/class-wp-meta-query2.php Mon Jun 17 00:52:41 2019
3@@ -296,0 +297,21 @@ class WP_Meta_Query {
4+ /**
5+ * Return the appropriate format for the given meta query value parameter
6+ *
7+ * @since 5.2.1
8+ *
9+ * @param string $type MySQL type to cast meta_value.
10+ * @return string MySQL type.
11+ */
12+ public function get_value_format_for_type( $type = '' ) {
13+
14+ $format = "%s";
15+
16+ if ( empty( $type ) ) {
17+ return '%s';
18+ }
19+
20+ $meta_type = strtoupper( $type );
21+
22+ if ( 'INTEGER' === $meta_type ) {
23+ $format = '%d';
24+ }
25@@ -297,0 +319,2 @@ class WP_Meta_Query {
26+ return $format;
27+ }
28@@ -615,0 +639,2 @@ class WP_Meta_Query {
29+ $meta_value_format = $this->get_value_format_for_type( $_meta_type );
30+
31@@ -619 +644 @@ class WP_Meta_Query {
32- $meta_compare_string = '(' . substr( str_repeat( ',%s', count( $meta_value ) ), 1 ) . ')';
33+ $meta_compare_string = '(' . substr( str_repeat( ",$meta_value_format", count( $meta_value ) ), 1 ) . ')';
34@@ -626 +651 @@ class WP_Meta_Query {
35- $where = $wpdb->prepare( '%s AND %s', $meta_value );
36+ $where = $wpdb->prepare( "$meta_value_format AND $meta_value_format", $meta_value );
37@@ -632 +657 @@ class WP_Meta_Query {
38- $where = $wpdb->prepare( '%s', $meta_value );
39+ $where = $wpdb->prepare( "$meta_value_format", $meta_value );
40@@ -638 +663 @@ class WP_Meta_Query {
41- $where = $wpdb->prepare( '%s', $meta_value );
42+ $where = $wpdb->prepare( "$meta_value_format", $meta_value );
43@@ -647 +672 @@ class WP_Meta_Query {
44- $where = $wpdb->prepare( '%s', $meta_value );
45+ $where = $wpdb->prepare( "$meta_value_format", $meta_value );