On this page
WP_Meta_Query::__construct( array $meta_query = false )
Constructor.
Parameters
$meta_queryarray 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.
relationstringOptional. The MySQL keyword used to join the clauses of the query.
Accepts'AND'or'OR'. Default'AND'....$0arrayOptional. An array of first-order clause parameters, or another fully-formed meta query.keystring|string[]Meta key or keys to filter by.compare_keystringMySQL operator used for comparing the $key. Accepts:
'=''!=''LIKE'- 'NOT LIKE'
'IN'- 'NOT IN'
'REGEXP'- 'NOT REGEXP'
'RLIKE','EXISTS'(alias of'=')- 'NOT EXISTS' (alias of
'!=') Default is'IN'when$keyis an array,'='otherwise.
type_keystringMySQL data type that the meta_key column will be CAST to for comparisons. Accepts'BINARY'for case-sensitive regular expression comparisons. Default is''.valuestring|string[]Meta value or values to filter by.comparestringMySQL operator used for comparing the $value. Accepts:
'=','!=''>''>=''<''<=''LIKE'- 'NOT LIKE'
'IN'- 'NOT IN'
'BETWEEN'- 'NOT BETWEEN'
'REGEXP'- 'NOT REGEXP'
'RLIKE''EXISTS'- 'NOT EXISTS' Default is
'IN'when$valueis an array,'='otherwise.
typestringMySQL data type that the meta_value column will be CAST to for comparisons. Accepts:
'NUMERIC''BINARY''CHAR''DATE''DATETIME''DECIMAL''SIGNED''TIME''UNSIGNED'Default is'CHAR'.
Default:
falseSource
File:
wp-includes/class-wp-meta-query.php. View all referencespublic function __construct( $meta_query = false ) { if ( ! $meta_query ) { return; } if ( isset( $meta_query['relation'] ) && 'OR' === strtoupper( $meta_query['relation'] ) ) { $this->relation = 'OR'; } else { $this->relation = 'AND'; } $this->queries = $this->sanitize_query( $meta_query ); }Related
Uses
Uses Description WP_Meta_Query::sanitize_query() wp-includes/class-wp-meta-query.php Ensure the ‘meta_query’ argument passed to the class constructor is well-formed.
Used By
Used By Description WP_Term_Query::get_terms() wp-includes/class-wp-term-query.php Retrieves the query results.
WP_Site_Query::get_sites() wp-includes/class-wp-site-query.php Retrieves a list of sites matching the query vars.
WP_Comment_Query::get_comments() wp-includes/class-wp-comment-query.php Get a list of comments matching the query vars.
WP_Query::get_posts() wp-includes/class-wp-query.php Retrieves an array of posts based on query variables.
WP_User_Query::prepare_query() wp-includes/class-wp-user-query.php Prepares the query variables.
get_meta_sql() wp-includes/meta.php Given a meta query, generates SQL clauses to be appended to a main query.
WP_Meta_Query::parse_query_vars() wp-includes/class-wp-meta-query.php Constructs a meta query based on ‘meta_*’ query vars
Changelog
Version Description 5.3.0 Increased the number of operators available to $compare_key. Introduced$type_key, which enables the$keyto be cast to a new data type for comparisons.5.1.0 Introduced $compare_keyclause parameter, which enables LIKE key matches.4.2.0 Introduced support for naming query clauses by associative array keys. 3.2.0 Introduced.
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/classes/wp_meta_query/__construct