*
* 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.
*
/**
* 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
* @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'.
return false;
}
+ $this->table_aliases = array();
+
$this->meta_table = $meta_table;
$this->meta_id_column = sanitize_key( $type . '_id' );
}
/**
- * Filter the meta query's generated SQL.
+ * Filters the meta query's generated SQL.
*
* @since 3.1.0
*
/**
* 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
}
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}";
+ }
}
}
* 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
}
/**
- * 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
*