WP_Meta_Query::__construct( array $meta_query = false )
Constructor.
Parameters
- $meta_query
-
(Optional) 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.<br>
- 'relation'
(string) Optional. The MySQL keyword used to join the clauses of the query.<br> Accepts 'AND' or 'OR'. Default 'AND'.<br> - '...$0'
(array) Optional. An array of first-order clause parameters, or another fully-formed meta query.<br>- 'key'
(string|string[]) Meta key or keys to filter by.<br> - 'compare_key'
(string) MySQL operator used for comparing the $key. Accepts:<br>- '='<br>
- '!='<br>
- 'LIKE'<br>
- 'NOT LIKE'<br>
- 'IN'<br>
- 'NOT IN'<br>
- 'REGEXP'<br>
- 'NOT REGEXP'<br>
- 'RLIKE',<br>
- 'EXISTS' (alias of '=')<br>
- 'NOT EXISTS' (alias of '!=') Default is 'IN' when
$key
is an array, '=' otherwise.<br>
- 'type_key'
(string) MySQL data type that the meta_key column will be CAST to for comparisons. Accepts 'BINARY' for case-sensitive regular expression comparisons. Default is ''.<br> - 'value'
(string|string[]) Meta value or values to filter by.<br> - 'compare'
(string) MySQL operator used for comparing the $value. Accepts:<br> - '=',<br>
- '!='<br>
- '>'<br>
- '>='<br>
- '<'<br>
- '<='<br>
- 'LIKE'<br>
- 'NOT LIKE'<br>
- 'IN'<br>
- 'NOT IN'<br>
- 'BETWEEN'<br>
- 'NOT BETWEEN'<br>
- 'REGEXP'<br>
- 'NOT REGEXP'<br>
- 'RLIKE'<br>
- 'EXISTS'<br>
- 'NOT EXISTS' Default is 'IN' when
$value
is an array, '=' otherwise.<br>
- 'key'
- 'type'
(string) MySQL data type that the meta_value column will be CAST to for comparisons. Accepts:<br> - 'NUMERIC'<br>
- 'BINARY'<br>
- 'CHAR'<br>
- 'DATE'<br>
- 'DATETIME'<br>
- 'DECIMAL'<br>
- 'SIGNED'<br>
- 'TIME'<br>
- 'UNSIGNED' Default is 'CHAR'.<br>
Default value: false
- 'relation'
Source
File: wp-includes/class-wp-meta-query.php
public function __construct( $meta_query = false ) {
if ( !$meta_query )
return;
if ( isset( $meta_query['relation'] ) && strtoupper( $meta_query['relation'] ) == 'OR' ) {
$this->relation = 'OR';
} else {
$this->relation = 'AND';
}
$this->queries = $this->sanitize_query( $meta_query );
}
Changelog
Version | Description |
---|---|
5.3.0 | Increased the number of operators available to $compare_key . Introduced $type_key , which enables the $key to be cast to a new data type for comparisons. |
5.1.0 | Introduced $compare_key clause parameter, which enables LIKE key matches. |
4.2.0 | Introduced support for naming query clauses by associative array keys. |
3.2.0 | Introduced. |