]> scripts.mit.edu Git - autoinstalls/wordpress.git/blobdiff - wp-includes/class-wp-meta-query.php
Wordpress 4.6
[autoinstalls/wordpress.git] / wp-includes / class-wp-meta-query.php
index 5716b5f20f66a7cdbc57a43ecc001f04c0d4e21b..4019912019883967d6def5b40f8a27095444a3cd 100644 (file)
@@ -12,7 +12,8 @@
  *
  * Used for generating SQL clauses that filter a primary query according to metadata keys and values.
  *
- * `WP_Meta_Query` is a helper that allows primary query classes, such as {@see WP_Query} and {@see WP_User_Query},
+ * WP_Meta_Query is a helper that allows primary query classes, such as WP_Query and WP_User_Query,
+ *
  * to filter their results by object metadata, by generating `JOIN` and `WHERE` subclauses to be attached
  * to the primary SQL query string.
  *
@@ -24,7 +25,7 @@ class WP_Meta_Query {
        /**
         * Array of metadata queries.
         *
-        * See {@see WP_Meta_Query::__construct()} for information on meta query arguments.
+        * See WP_Meta_Query::__construct() for information on meta query arguments.
         *
         * @since 3.2.0
         * @access public
@@ -113,8 +114,8 @@ class WP_Meta_Query {
         * @access public
         *
         * @param array $meta_query {
-        *     Array of meta query clauses. When first-order clauses use strings as their array keys, they may be
-        *     referenced in the 'orderby' parameter of the parent query.
+        *     Array of meta query clauses. When first-order clauses or sub-clauses use strings as
+        *     their array keys, they may be referenced in the 'orderby' parameter of the parent query.
         *
         *     @type string $relation Optional. The MySQL keyword used to join
         *                            the clauses of the query. Accepts 'AND', or 'OR'. Default 'AND'.
@@ -326,6 +327,8 @@ class WP_Meta_Query {
                        return false;
                }
 
+               $this->table_aliases = array();
+
                $this->meta_table     = $meta_table;
                $this->meta_id_column = sanitize_key( $type . '_id' );
 
@@ -343,7 +346,7 @@ class WP_Meta_Query {
                }
 
                /**
-                * Filter the meta query's generated SQL.
+                * Filters the meta query's generated SQL.
                 *
                 * @since 3.1.0
                 *
@@ -360,8 +363,8 @@ class WP_Meta_Query {
        /**
         * Generate SQL clauses to be appended to a main query.
         *
-        * Called by the public {@see WP_Meta_Query::get_sql()}, this method
-        * is abstracted out to maintain parity with the other Query classes.
+        * Called by the public WP_Meta_Query::get_sql(), this method is abstracted
+        * out to maintain parity with the other Query classes.
         *
         * @since 4.1.0
         * @access protected
@@ -631,7 +634,11 @@ class WP_Meta_Query {
                        }
 
                        if ( $where ) {
-                               $sql_chunks['where'][] = "CAST($alias.meta_value AS {$meta_type}) {$meta_compare} {$where}";
+                               if ( 'CHAR' === $meta_type ) {
+                                       $sql_chunks['where'][] = "$alias.meta_value {$meta_compare} {$where}";
+                               } else {
+                                       $sql_chunks['where'][] = "CAST($alias.meta_value AS {$meta_type}) {$meta_compare} {$where}";
+                               }
                        }
                }
 
@@ -672,8 +679,8 @@ class WP_Meta_Query {
         * An existing alias is compatible if (a) it is a sibling of `$clause`
         * (ie, it's under the scope of the same relation), and (b) the combination
         * of operator and relation between the clauses allows for a shared table join.
-        * In the case of {@see WP_Meta_Query}, this only applies to 'IN' clauses that
-        * are connected by the relation 'OR'.
+        * In the case of WP_Meta_Query, this only applies to 'IN' clauses that are
+        * connected by the relation 'OR'.
         *
         * @since 4.1.0
         * @access protected
@@ -716,7 +723,7 @@ class WP_Meta_Query {
                }
 
                /**
-                * Filter the table alias identified as compatible with the current clause.
+                * Filters the table alias identified as compatible with the current clause.
                 *
                 * @since 4.1.0
                 *