diff --git src/wp-includes/meta.php src/wp-includes/meta.php
index e3c43cf..ba23352 100644
--- src/wp-includes/meta.php
+++ src/wp-includes/meta.php
@@ -882,6 +882,46 @@ class WP_Meta_Query {
 	public $relation;
 
 	/**
+	 * Table aliases used in the query currently being built.
+	 *
+	 * @access protected
+	 * @var array
+	 */
+	protected $table_aliases = array();
+
+	/**
+	 * Database table to query for the metadata.
+	 *
+	 * @access public
+	 * @var string
+	 */
+	public $meta_table;
+
+	/**
+	 * Column in meta_table that represents the ID of the object the metadata belongs to.
+	 *
+	 * @access public
+	 * @var string
+	 */
+	public $meta_id_column;
+
+	/**
+	 * Database table that where the metadata's objects are stored (eg $wpdb->users)
+	 *
+	 * @access public
+	 * @var string
+	 */
+	public $primary_table;
+
+	/**
+	 * Column in primary_table that represents the ID of the object.
+	 *
+	 * @access public
+	 * @var string
+	 */
+	public $primary_id_column;
+
+	/**
 	 * Constructor
 	 *
 	 * @param array $meta_query (optional) A meta query
@@ -896,14 +936,63 @@ class WP_Meta_Query {
 			$this->relation = 'AND';
 		}
 
-		$this->queries = array();
+		$this->queries = self::clean_queries( $meta_query );
+	}
 
-		foreach ( $meta_query as $key => $query ) {
-			if ( ! is_array( $query ) )
-				continue;
 
-			$this->queries[] = $query;
+
+	/**
+	 * Ensure that the meta_query argument passed to the class constructor is well-formed.
+	 *
+	 * Eliminates empty items and ensures that a 'relation' is set.
+	 *
+	 * @param  array $queries
+	 * @return array
+	 */
+	public static function clean_queries( $queries ) {
+		$clean_queries = array();
+
+		if ( ! is_array( $queries ) ) {
+			return $clean_queries;
+		}
+
+		foreach ( $queries as $key => $query ) {
+			if ( 'relation' === $key ) {
+				$relation = $query;
+
+			// The presence of a 'key' or 'value' key indicates
+			// that this is a first-order clause
+			} else if ( isset( $query['key'] ) || isset( $query['value'] ) ) {
+				$clean_queries[] = $query;
+
+			// Otherwise, it's a nested query
+			} else {
+				$cleaned_query = self::clean_queries( $query );
+
+				if ( ! empty( $cleaned_query ) ) {
+					$clean_queries[] = $cleaned_query;
+				}
+			}
 		}
+
+		if ( empty( $clean_queries ) ) {
+			return $clean_queries;
+		}
+
+		// Sanitize the 'relation' key
+		if ( isset( $relation ) && 'OR' === strtoupper( $relation ) ) {
+			$clean_queries['relation'] = 'OR';
+
+		// If there is only a single clause, call the relation 'OR'.
+		// This value will not actually be used to join clauses, but it
+		// simplifies the logic around combining key-only queries
+		} else if ( 1 === count( $clean_queries ) ) {
+			$clean_queries['relation'] = 'OR';
+		} else {
+			$clean_queries['relation'] = 'AND';
+		}
+
+		return $clean_queries;
 	}
 
 	/**
@@ -958,125 +1047,164 @@ class WP_Meta_Query {
 	}
 
 	/**
-	 * Generates SQL clauses to be appended to a main query.
+	 * Generate the SQL clauses for a query array.
 	 *
-	 * @since 3.2.0
-	 * @access public
+	 * In the case of a nested query, this method recurses to generate
+	 * properly nested SQL.
 	 *
-	 * @param string $type Type of meta
-	 * @param string $primary_table
-	 * @param string $primary_id_column
-	 * @param object $context (optional) The main query object
-	 * @return array( 'join' => $join_sql, 'where' => $where_sql )
+	 * @param  array $query Query to parse.
+	 * @param  int   $depth Optional. Number of tree levels deep we
+	 *                     currently are. Used to calculate indentation.
+	 * @return array Array of 'join' and 'where' clauses.
 	 */
-	public function get_sql( $type, $primary_table, $primary_id_column, $context = null ) {
-		global $wpdb;
-
-		if ( ! $meta_table = _get_meta_table( $type ) )
-			return false;
-
-		$meta_id_column = sanitize_key( $type . '_id' );
-
-		$join = array();
-		$where = array();
-
-		$key_only_queries = array();
-		$queries = array();
+	public function get_sql_for_query( $query, $depth = 0 ) {
+		$sql_chunks = array(
+			'join'  => array(),
+			'where' => array(),
+		);
 
-		// Split out the queries with empty arrays as value
-		foreach ( $this->queries as $k => $q ) {
-			if ( isset( $q['value'] ) && is_array( $q['value'] ) && empty( $q['value'] ) ) {
-				$key_only_queries[$k] = $q;
-				unset( $this->queries[$k] );
-			}
-		}
+		$sql = array(
+			'join'  => '',
+			'where' => '',
+		);
 
-		// Split out the meta_key only queries (we can only do this for OR)
-		if ( 'OR' == $this->relation ) {
-			foreach ( $this->queries as $k => $q ) {
-				if ( ( empty( $q['compare'] ) || 'NOT EXISTS' != $q['compare'] ) && ! array_key_exists( 'value', $q ) && ! empty( $q['key'] ) )
-					$key_only_queries[$k] = $q;
-				else
-					$queries[$k] = $q;
-			}
-		} else {
-			$queries = $this->queries;
+		$indent = '';
+		for ( $i = 0; $i < $depth; $i++ ) {
+			$indent .= "\t";
 		}
 
-		// Specify all the meta_key only queries in one go
-		if ( $key_only_queries ) {
-			$join[]  = "INNER JOIN $meta_table ON $primary_table.$primary_id_column = $meta_table.$meta_id_column";
+		foreach ( $query as $key => $clause ) {
+			if ( 'relation' === $key ) {
+				$relation = $query['relation'];
+			} else {
+				// This is a subquery
+				if ( isset( $clause['relation'] ) ) {
+					$clause_sql = $this->get_sql_for_query( $clause, $depth + 1 );
+
+					$sql_chunks['where'][] = $clause_sql['where'];
+					$sql_chunks['join'][]  = $clause_sql['join'];
+
+
+				// This is a first-order clause
+				} else {
+					$clause_sql = $this->get_sql_for_clause( $clause, $query );
+
+					$where_count = count( $clause_sql['where'] );
+					if ( ! $where_count ) {
+						$sql_chunks['where'][] = '';
+					} else if ( 1 === $where_count ) {
+						$sql_chunks['where'][] = $clause_sql['where'][0];
+					} else {
+						$sql_chunks['where'][] = '( ' . implode( ' AND ', $clause_sql['where'] ) . ' )';
+					}
+					$sql_chunks['join'] = array_merge( $sql_chunks['join'], $clause_sql['join'] );
+				}
 
-			foreach ( $key_only_queries as $key => $q )
-				$where["key-only-$key"] = $wpdb->prepare( "$meta_table.meta_key = %s", trim( $q['key'] ) );
+			}
 		}
 
-		foreach ( $queries as $k => $q ) {
-			$meta_key = isset( $q['key'] ) ? trim( $q['key'] ) : '';
-			$meta_type = $this->get_cast_for_type( isset( $q['type'] ) ? $q['type'] : '' );
-
-			if ( array_key_exists( 'value', $q ) && is_null( $q['value'] ) )
-				$q['value'] = '';
+		$sql['join'] = implode( ' ', array_unique( $sql_chunks['join'] ) );
+		$sql['where'] = '( ' . "\n\t" . $indent . implode( ' ' . "\n\t" . $indent . $relation . ' ' . "\n\t" . $indent, $sql_chunks['where'] ) . "\n" . $indent . ')' . "\n";
 
-			$meta_value = isset( $q['value'] ) ? $q['value'] : null;
+		return $sql;
+	}
 
-			if ( isset( $q['compare'] ) )
-				$meta_compare = strtoupper( $q['compare'] );
-			else
-				$meta_compare = is_array( $meta_value ) ? 'IN' : '=';
+	/**
+	 * Generate SQL JOIN and WHERE clauses for a first-order query clause.
+	 *
+	 * "First-order" means that it's an array with a 'key' or 'value'.
+	 *
+	 * @param  array         $clause       Query clause.
+	 * @param  WP_Meta_Query $parent_query Query object.
+	 * @return array
+	 */
+	public function get_sql_for_clause( $clause, $parent_query ) {
+		global $wpdb;
 
-			if ( ! in_array( $meta_compare, array(
-				'=', '!=', '>', '>=', '<', '<=',
-				'LIKE', 'NOT LIKE',
-				'IN', 'NOT IN',
-				'BETWEEN', 'NOT BETWEEN',
-				'NOT EXISTS',
-				'REGEXP', 'NOT REGEXP', 'RLIKE'
-			) ) )
-				$meta_compare = '=';
+		$sql_chunks = array(
+			'where' => array(),
+			'join' => array(),
+		);
 
-			$i = count( $join );
-			$alias = $i ? 'mt' . $i : $meta_table;
+		$i = count( $this->table_aliases );
+		$alias = $i ? 'mt' . $i : $this->meta_table;
 
-			if ( 'NOT EXISTS' == $meta_compare ) {
-				$join[$i]  = "LEFT JOIN $meta_table";
-				$join[$i] .= $i ? " AS $alias" : '';
-				$join[$i] .= " ON ($primary_table.$primary_id_column = $alias.$meta_id_column AND $alias.meta_key = '$meta_key')";
+		if ( isset( $clause['compare'] ) ) {
+			$meta_compare = strtoupper( $clause['compare'] );
+		} else {
+			$meta_compare = isset( $clause['value'] ) && is_array( $clause['value'] ) ? 'IN' : '=';
+		}
 
-				$where[$k] = ' ' . $alias . '.' . $meta_id_column . ' IS NULL';
+		if ( ! in_array( $meta_compare, array(
+			'=', '!=', '>', '>=', '<', '<=',
+			'LIKE', 'NOT LIKE',
+			'IN', 'NOT IN',
+			'BETWEEN', 'NOT BETWEEN',
+			'EXISTS', 'NOT EXISTS',
+			'REGEXP', 'NOT REGEXP', 'RLIKE'
+		) ) ) {
+			$meta_compare = '=';
+		}
 
-				continue;
+		// There are a number of different query structures that get
+		// built in different ways
+		// 1. Key-only clauses - (a) clauses without a 'value' key that
+		//    appear in the context of an OR relation and do not use
+		//    'NOT EXISTS' as the 'compare', or (b) clauses with an
+		//    empty array for 'value'
+		if ( ! empty( $clause['key'] ) && (
+			( ! array_key_exists( 'value', $clause ) && 'NOT EXISTS' !== $meta_compare && 'OR' === $parent_query['relation'] ) ||
+			( isset( $clause['value'] ) && is_array( $clause['value'] ) && empty( $clause['value'] ) )
+		) ) {
+
+			$alias = $this->meta_table;
+			$sql_chunks['join'][] = " INNER JOIN $this->meta_table ON ($this->primary_table.$this->primary_id_column = $alias.$this->meta_id_column)";
+			$sql_chunks['where'][] = $wpdb->prepare( "$this->meta_table.meta_key = %s", trim( $clause['key'] ) );
+
+		// 2. NOT EXISTS
+		} else if ( 'NOT EXISTS' === $meta_compare ) {
+			$join  = " LEFT JOIN $this->meta_table";
+			$join .= $i ? " AS $alias" : '';
+			$join .= $wpdb->prepare( " ON ($this->primary_table.$this->primary_id_column = $alias.$this->meta_id_column AND $alias.meta_key = %s )", $clause['key'] );
+			$sql_chunks['join'][] = $join;
+
+			$sql_chunks['where'][] = $alias . '.' . $this->meta_id_column . ' IS NULL';
+
+		// 3. EXISTS and other key-only queries
+		} else if ( 'EXISTS' === $meta_compare || ( ! empty( $clause['key'] ) && ! array_key_exists( 'value', $clause ) ) ) {
+			$join  = " INNER JOIN $this->meta_table";
+			$join .= $i ? " AS $alias" : '';
+			$join .= " ON ( $this->primary_table.$this->primary_id_column = $alias.$this->meta_id_column )";
+			$sql_chunks['join'][] = $join;
+
+			$sql_chunks['where'][] = $wpdb->prepare( $alias . '.meta_key = %s', trim( $clause['key'] ) );
+
+		// 4. Clauses that have a value
+		} else if ( array_key_exists( 'value', $clause ) ) {
+			$join  = " INNER JOIN $this->meta_table";
+			$join .= $i ? " AS $alias" : '';
+			$join .= " ON ($this->primary_table.$this->primary_id_column = $alias.$this->meta_id_column)";
+			$sql_chunks['join'][] = $join;
+
+			if ( ! empty( $clause['key'] ) ) {
+				$sql_chunks['where'][] = $wpdb->prepare( "$alias.meta_key = %s", trim( $clause['key'] ) );
 			}
 
-			$join[$i]  = "INNER JOIN $meta_table";
-			$join[$i] .= $i ? " AS $alias" : '';
-			$join[$i] .= " ON ($primary_table.$primary_id_column = $alias.$meta_id_column)";
+			$meta_type = $this->get_cast_for_type( isset( $clause['type'] ) ? $clause['type'] : '' );
 
-			$where[$k] = '';
-			if ( !empty( $meta_key ) )
-				$where[$k] = $wpdb->prepare( "$alias.meta_key = %s", $meta_key );
-
-			if ( is_null( $meta_value ) ) {
-				if ( empty( $where[$k] ) )
-					unset( $join[$i] );
-				continue;
-			}
+			$meta_value = isset( $clause['value'] ) ? $clause['value'] : '';
 
 			if ( in_array( $meta_compare, array( 'IN', 'NOT IN', 'BETWEEN', 'NOT BETWEEN' ) ) ) {
-				if ( ! is_array( $meta_value ) )
+				if ( ! is_array( $meta_value ) ) {
 					$meta_value = preg_split( '/[,\s]+/', $meta_value );
-
-				if ( empty( $meta_value ) ) {
-					unset( $join[$i] );
-					continue;
 				}
 			} else {
 				$meta_value = trim( $meta_value );
 			}
 
-			if ( 'IN' == substr( $meta_compare, -2) ) {
+			if ( 'IN' == substr( $meta_compare, -2 ) ) {
 				$meta_compare_string = '(' . substr( str_repeat( ',%s', count( $meta_value ) ), 1 ) . ')';
-			} elseif ( 'BETWEEN' == substr( $meta_compare, -7) ) {
+			} elseif ( 'BETWEEN' == substr( $meta_compare, -7 ) ) {
 				$meta_value = array_slice( $meta_value, 0, 2 );
 				$meta_compare_string = '%s AND %s';
 			} elseif ( 'LIKE' == $meta_compare || 'NOT LIKE' == $meta_compare ) {
@@ -1086,22 +1214,50 @@ class WP_Meta_Query {
 				$meta_compare_string = '%s';
 			}
 
-			if ( ! empty( $where[$k] ) )
-				$where[$k] .= ' AND ';
+			$sql_chunks['where'][] = $wpdb->prepare( "CAST($alias.meta_value AS {$meta_type}) {$meta_compare} {$meta_compare_string}", $meta_value );
+		}
 
-			$where[$k] = ' (' . $where[$k] . $wpdb->prepare( "CAST($alias.meta_value AS {$meta_type}) {$meta_compare} {$meta_compare_string})", $meta_value );
+		// Multiple WHERE clauses (for meta_key and meta_value) should
+		// be joined in parentheses
+		if ( 1 < count( $sql_chunks['where'] ) ) {
+			$sql_chunks['where'] = array( '( ' . implode( ' AND ', $sql_chunks['where'] ) . ' )' );
 		}
 
-		$where = array_filter( $where );
+		$this->table_aliases[] = $alias;
 
-		if ( empty( $where ) )
-			$where = '';
-		else
-			$where = ' AND (' . implode( "\n{$this->relation} ", $where ) . ' )';
+		return $sql_chunks;
+	}
+
+	/**
+	 * Generates SQL clauses to be appended to a main query.
+	 *
+	 * @since 3.2.0
+	 * @access public
+	 *
+	 * @param string $type Type of meta
+	 * @param string $primary_table
+	 * @param string $primary_id_column
+	 * @param object $context (optional) The main query object
+	 * @return array( 'join' => $join_sql, 'where' => $where_sql )
+	 */
+	public function get_sql( $type, $primary_table, $primary_id_column, $context = null ) {
+		global $wpdb;
 
-		$join = implode( "\n", $join );
-		if ( ! empty( $join ) )
-			$join = ' ' . $join;
+		if ( ! $meta_table = _get_meta_table( $type ) ) {
+			return false;
+		}
+
+		$this->meta_table     = $meta_table;
+		$this->meta_id_column = sanitize_key( $type . '_id' );
+
+		$this->primary_table     = $primary_table;
+		$this->primary_id_column = $primary_id_column;
+
+		$sql = $this->get_sql_for_query( $this->queries );
+
+		if ( ! empty( $sql['where'] ) ) {
+			$sql['where'] = ' AND ' . "\n" . $sql['where'] . "\n";
+		}
 
 		/**
 		 * Filter the meta query's generated SQL.
@@ -1119,7 +1275,7 @@ class WP_Meta_Query {
 		 *     @type object $context           The main query object.
 		 * }
 		 */
-		return apply_filters_ref_array( 'get_meta_sql', array( compact( 'join', 'where' ), $this->queries, $type, $primary_table, $primary_id_column, $context ) );
+		return apply_filters_ref_array( 'get_meta_sql', array( $sql, $this->queries, $type, $primary_table, $primary_id_column, $context ) );
 	}
 }
 
diff --git tests/phpunit/tests/meta/nested.php tests/phpunit/tests/meta/nested.php
new file mode 100644
index 0000000..7e9524d
--- /dev/null
+++ tests/phpunit/tests/meta/nested.php
@@ -0,0 +1,305 @@
+<?php
+
+/**
+ * @group meta
+ */
+class WP_Tests_Nested_Meta extends WP_UnitTestCase {
+	public function test_clean_queries_single_query() {
+		$expected = array(
+			'relation' => 'OR',
+			array(
+				'key' => 'foo',
+				'value' => 'bar',
+			),
+		);
+
+		$found = WP_Meta_Query::clean_queries( array(
+			array(
+				'key' => 'foo',
+				'value' => 'bar',
+			),
+		) );
+
+		$this->assertEquals( $expected, $found );
+	}
+
+	public function test_clean_queries_multiple_first_order_queries_relation_default() {
+		$expected = array(
+			'relation' => 'AND',
+			array(
+				'key' => 'foo',
+				'value' => 'bar',
+			),
+			array(
+				'key' => 'foo2',
+				'value' => 'bar2',
+			),
+		);
+
+		$found = WP_Meta_Query::clean_queries( array(
+			array(
+				'key' => 'foo',
+				'value' => 'bar',
+			),
+			array(
+				'key' => 'foo2',
+				'value' => 'bar2',
+			),
+		) );
+
+		$this->assertEquals( $expected, $found );
+	}
+
+	public function test_clean_queries_multiple_first_order_queries_relation_or() {
+		$expected = array(
+			'relation' => 'OR',
+			array(
+				'key' => 'foo',
+				'value' => 'bar',
+			),
+			array(
+				'key' => 'foo2',
+				'value' => 'bar2',
+			),
+		);
+
+		$found = WP_Meta_Query::clean_queries( array(
+			'relation' => 'OR',
+			array(
+				'key' => 'foo',
+				'value' => 'bar',
+			),
+			array(
+				'key' => 'foo2',
+				'value' => 'bar2',
+			),
+		) );
+
+		$this->assertEquals( $expected, $found );
+	}
+
+	public function test_clean_queries_multiple_first_order_queries_relation_or_lowercase() {
+		$expected = array(
+			'relation' => 'OR',
+			array(
+				'key' => 'foo',
+				'value' => 'bar',
+			),
+			array(
+				'key' => 'foo2',
+				'value' => 'bar2',
+			),
+		);
+
+		$found = WP_Meta_Query::clean_queries( array(
+			'relation' => 'or',
+			array(
+				'key' => 'foo',
+				'value' => 'bar',
+			),
+			array(
+				'key' => 'foo2',
+				'value' => 'bar2',
+			),
+		) );
+
+		$this->assertEquals( $expected, $found );
+	}
+
+	public function test_clean_queries_multiple_first_order_queries_invalid_relation() {
+		$expected = array(
+			'relation' => 'AND',
+			array(
+				'key' => 'foo',
+				'value' => 'bar',
+			),
+			array(
+				'key' => 'foo2',
+				'value' => 'bar2',
+			),
+		);
+
+		$found = WP_Meta_Query::clean_queries( array(
+			'relation' => 'FOO',
+			array(
+				'key' => 'foo',
+				'value' => 'bar',
+			),
+			array(
+				'key' => 'foo2',
+				'value' => 'bar2',
+			),
+		) );
+
+		$this->assertEquals( $expected, $found );
+	}
+
+	public function test_clean_queries_single_query_which_is_a_nested_query() {
+		$expected = array(
+			'relation' => 'OR',
+			array(
+				'relation' => 'AND',
+				array(
+					'key' => 'foo',
+					'value' => 'bar',
+				),
+				array(
+					'key' => 'foo2',
+					'value' => 'bar2',
+				),
+			)
+		);
+
+		$found = WP_Meta_Query::clean_queries( array(
+			array(
+				array(
+					'key' => 'foo',
+					'value' => 'bar',
+				),
+				array(
+					'key' => 'foo2',
+					'value' => 'bar2',
+				),
+			),
+		) );
+
+		$this->assertEquals( $expected, $found );
+	}
+
+	public function test_clean_queries_multiple_nested_queries() {
+		$expected = array(
+			'relation' => 'OR',
+			array(
+				'relation' => 'AND',
+				array(
+					'key' => 'foo',
+					'value' => 'bar',
+				),
+				array(
+					'key' => 'foo2',
+					'value' => 'bar2',
+				),
+			),
+			array(
+				'relation' => 'AND',
+				array(
+					'key' => 'foo3',
+					'value' => 'bar3',
+				),
+				array(
+					'key' => 'foo4',
+					'value' => 'bar4',
+				),
+			),
+		);
+
+		$found = WP_Meta_Query::clean_queries( array(
+			'relation' => 'OR',
+			array(
+				array(
+					'key' => 'foo',
+					'value' => 'bar',
+				),
+				array(
+					'key' => 'foo2',
+					'value' => 'bar2',
+				),
+			),
+			array(
+				array(
+					'key' => 'foo3',
+					'value' => 'bar3',
+				),
+				array(
+					'key' => 'foo4',
+					'value' => 'bar4',
+				),
+			),
+		) );
+
+		$this->assertEquals( $expected, $found );
+	}
+
+	public function test_meta_query_nested() {
+		$p1 = $this->factory->post->create();
+		$p2 = $this->factory->post->create();
+		$p3 = $this->factory->post->create();
+
+		add_post_meta( $p1, 'foo', 'bar' );
+		add_post_meta( $p2, 'foo2', 'bar' );
+		add_post_meta( $p3, 'foo2', 'bar' );
+		add_post_meta( $p3, 'foo3', 'bar' );
+
+		$query = new WP_Query( array(
+			'update_post_meta_cache' => false,
+			'update_term_meta_cache' => false,
+			'fields' => 'ids',
+			'meta_query' => array(
+				'relation' => 'OR',
+				array(
+					'key' => 'foo',
+					'value' => 'bar',
+				),
+				array(
+					'relation' => 'AND',
+					array(
+						'key' => 'foo2',
+						'value' => 'bar',
+					),
+					array(
+						'key' => 'foo3',
+						'value' => 'bar',
+					),
+				),
+			),
+		) );
+
+		$expected = array( $p1, $p3 );
+		$this->assertEqualSets( $expected, $query->posts );
+	}
+
+	public function test_meta_query_nested_two_levels_deep() {
+		$p1 = $this->factory->post->create();
+		$p2 = $this->factory->post->create();
+		$p3 = $this->factory->post->create();
+
+		add_post_meta( $p1, 'foo', 'bar' );
+		add_post_meta( $p3, 'foo2', 'bar' );
+		add_post_meta( $p3, 'foo3', 'bar' );
+		add_post_meta( $p3, 'foo4', 'bar' );
+
+		$query = new WP_Query( array(
+			'update_post_meta_cache' => false,
+			'update_term_meta_cache' => false,
+			'fields' => 'ids',
+			'meta_query' => array(
+				'relation' => 'OR',
+				array(
+					'key' => 'foo',
+					'value' => 'bar',
+				),
+				array(
+					'relation' => 'OR',
+					array(
+						'key' => 'foo2',
+						'value' => 'bar',
+					),
+					array(
+						'relation' => 'AND',
+						array(
+							'key' => 'foo3',
+							'value' => 'bar',
+						),
+						array(
+							'key' => 'foo4',
+							'value' => 'bar',
+						),
+					),
+				),
+			),
+		) );
+
+		$expected = array( $p1, $p3 );
+		$this->assertEqualSets( $expected, $query->posts );
+	}
+}
