X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/784f914b1e4b1c62d6657e86397c2e83bcee4295..607b7e02d77e7326161e8ec15639052d2040f745:/wp-includes/class-wp-meta-query.php diff --git a/wp-includes/class-wp-meta-query.php b/wp-includes/class-wp-meta-query.php index 5716b5f2..40199120 100644 --- a/wp-includes/class-wp-meta-query.php +++ b/wp-includes/class-wp-meta-query.php @@ -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 *