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.

  • 'relation'
    (string) Optional. The MySQL keyword used to join the clauses of the query. Accepts 'AND', or 'OR'. Default 'AND'.
  • (array) Optional. An array of first-order clause parameters, or another fully-formed meta query.
    • 'key'
      (string) Meta key to filter by.
    • 'value'
      (string) Meta value to filter by.
    • 'compare'
      (string) MySQL operator used for comparing the $value. Accepts '=', '!=', '>', '>=', '<', '<=', 'LIKE', 'NOT LIKE', 'IN', 'NOT IN', 'BETWEEN', 'NOT BETWEEN', 'REGEXP', 'NOT REGEXP', 'RLIKE', 'EXISTS' or 'NOT EXISTS'. Default is 'IN' when $value is an array, '=' otherwise.
    • 'type'
      (string) MySQL data type that the meta_value column will be CAST to for comparisons. Accepts 'NUMERIC', 'BINARY', 'CHAR', 'DATE', 'DATETIME', 'DECIMAL', 'SIGNED', 'TIME', or 'UNSIGNED'. Default is 'CHAR'.

Default value: false


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

Changelog
Version Description
WP-4.2.0 Introduced support for naming query clauses by associative array keys.
WP-3.2.0 Introduced.