Index: wp-includes/functions.php
===================================================================
--- wp-includes/functions.php	(revision 15714)
+++ wp-includes/functions.php	(working copy)
@@ -4257,62 +4257,6 @@
 }
 
 /*
- * Used internally to generate an SQL string for searching across multiple meta key = value pairs
- *
- * @access private
- * @since 3.1.0
- *
- * @param array $queries An array of queries
- * @param string $primary_table
- * @param string $primary_id_column
- * @param string $meta_table
- * @param string $meta_id_column
- * @return array( $join_sql, $where_sql )
- */
-function _wp_meta_sql( $queries, $primary_table, $primary_id_column, $meta_table, $meta_id_column ) {
-	global $wpdb;
-
-	$clauses = array();
-
-	$join = '';
-	$where = '';
-	$i = 0;
-	foreach ( $queries as $q ) {
-		$meta_key = isset( $q['key'] ) ? trim( $q['key'] ) : '';
-		$meta_value = isset( $q['value'] ) ? trim( $q['value'] ) : '';
-		$meta_compare = isset( $q['compare'] ) ? $q['compare'] : '=';
-
-		if ( !in_array( $meta_compare, array( '=', '!=', '>', '>=', '<', '<=', 'like' ) ) )
-			$meta_compare = '=';
-
-		if ( empty( $meta_key ) && empty( $meta_value ) )
-			continue;
-
-		$alias = $i ? 'mt' . $i : $meta_table;
-
-		$join .= "\nINNER JOIN $meta_table";
-		$join .= $i ? " AS $alias" : '';
-		$join .= " ON ($primary_table.$primary_id_column = $alias.$meta_id_column)";
-
-		$i++;
-
-		if ( !empty( $meta_key ) )
-			$where .= $wpdb->prepare( " AND $alias.meta_key = %s", $meta_key );
-
-		if ( empty( $meta_value ) )
-			continue;
-
-		if ( 'like' == $meta_compare ) {
-			$where .= $wpdb->prepare( " AND $alias.meta_value LIKE %s", '%' . like_escape( $meta_value ) . '%' );
-		} else {
-			$where .= $wpdb->prepare( " AND $alias.meta_value $meta_compare %s", $meta_value );
-		}
-	}
-
-	return array( $join, $where );
-}
-
-/*
  * Used internally to tidy up the search terms
  *
  * @access private
Index: wp-includes/user.php
===================================================================
--- wp-includes/user.php	(revision 15714)
+++ wp-includes/user.php	(working copy)
@@ -330,7 +330,7 @@
  *
  * @since 3.1.0
  */
-class WP_User_Query {
+class WP_User_Query extends WP_Object_Query {
 
 	/**
 	 * List of found user ids
@@ -444,11 +444,11 @@
 			$this->query_where .= _wp_search_sql( $search, array('user_login', 'user_nicename', 'user_email', 'user_url', 'display_name') );
 		}
 
+		$this->parse_meta_query( $qv );
+
 		$role = trim( $qv['role'] );
 		$blog_id = absint( $qv['blog_id'] );
 
-		$meta_queries = array();
-
 		if ( $blog_id ) {
 			$cap_meta_query = array();
 			$cap_meta_query['key'] = $wpdb->get_blog_prefix( $blog_id ) . 'capabilities';
@@ -458,20 +458,10 @@
 				$cap_meta_query['compare'] = 'like';
 			}
 
-			$meta_queries[] = $cap_meta_query;
+			$this->meta_query[] = $cap_meta_query;
 		}
 
-		$meta_query = array();
-		foreach ( array( 'key', 'value', 'compare' ) as $key ) {
-			if ( !empty( $qv[ "meta_$key" ] ) )
-				$meta_query[ $key ] = $qv[ "meta_$key" ];
-		}
-
-		if ( !empty( $meta_query ) ) {
-			$meta_queries[] = $meta_query;
-		}
-
-		list( $meta_join, $meta_where ) = _wp_meta_sql( $meta_queries, $wpdb->users, 'ID', $wpdb->usermeta, 'user_id' );
+		list( $meta_join, $meta_where ) = $this->get_meta_sql( $wpdb->users, 'ID', $wpdb->usermeta, 'user_id' );
 		$this->query_from .= $meta_join;
 		$this->query_where .= $meta_where;
 
Index: wp-includes/query.php
===================================================================
--- wp-includes/query.php	(revision 15714)
+++ wp-includes/query.php	(working copy)
@@ -641,7 +641,7 @@
  *
  * @since 1.5.0
  */
-class WP_Query {
+class WP_Query extends WP_Object_Query {
 
 	/**
 	 * Query vars set by the user
@@ -671,15 +671,6 @@
 	var $tax_query = array();
 
 	/**
-	 * Metadata query
-	 *
-	 * @since 3.1.0
-	 * @access public
-	 * @var array
-	 */
-	var $meta_query = array();
-
-	/**
 	 * Holds the data for a single object that is queried.
 	 *
 	 * Holds the contents of a post, page, category, attachment.
@@ -1389,20 +1380,8 @@
 				$this->is_tax = true;
 			}
 
-			if ( !empty( $qv['meta_query'] ) && is_array( $qv['meta_query'] ) ) {
-				$this->meta_query = $qv['meta_query'];
-			}
+			$this->parse_meta_query( $qv );
 
-			$meta_query = array();
-			foreach ( array( 'key', 'value', 'compare' ) as $key ) {
-				if ( !empty( $qv[ "meta_$key" ] ) )
-					$meta_query[ $key ] = $qv[ "meta_$key" ];
-			}
-
-			if ( !empty( $meta_query ) ) {
-				$this->meta_query[] = $meta_query;
-			}
-
 			if ( empty($qv['author']) || ($qv['author'] == '0') ) {
 				$this->is_author = false;
 			} else {
@@ -2211,7 +2190,7 @@
 			$where .= ')';
 		}
 
-		list( $meta_join, $meta_where ) = _wp_meta_sql( $this->meta_query, $wpdb->posts, 'ID', $wpdb->postmeta, 'post_id' );
+		list( $meta_join, $meta_where ) = $this->get_meta_sql( $wpdb->posts, 'ID', $wpdb->postmeta, 'post_id' );
 		$join .= $meta_join;
 		$where .= $meta_where;
 
Index: wp-includes/classes.php
===================================================================
--- wp-includes/classes.php	(revision 15708)
+++ wp-includes/classes.php	(working copy)
@@ -525,6 +525,105 @@
 }
 
 /**
+ * WordPress Query class.
+ *
+ * Abstract class for handling advanced queries
+ *
+ * @package WordPress
+ * @since 3.1.0
+ */
+class WP_Object_Query {
+
+	/**
+	 * Metadata query
+	 *
+	 * @since 3.1.0
+	 * @access public
+	 * @var array
+	 */
+	var $meta_query = array();
+
+	/*
+	 * Populates the $meta_query property
+	 *
+	 * @access private
+	 * @since 3.1.0
+	 *
+	 * @param array $qv The query variables
+	 */
+	function parse_meta_query( $qv ) {
+		if ( !empty( $qv['meta_query'] ) && is_array( $qv['meta_query'] ) ) {
+			$this->meta_query = $qv['meta_query'];
+		}
+
+		$meta_query = array();
+		foreach ( array( 'key', 'value', 'compare' ) as $key ) {
+			if ( !empty( $qv[ "meta_$key" ] ) )
+				$meta_query[ $key ] = $qv[ "meta_$key" ];
+		}
+
+		if ( !empty( $meta_query ) ) {
+			$this->meta_query[] = $meta_query;
+		}
+	}
+
+	/*
+	 * Used internally to generate an SQL string for searching across multiple meta key = value pairs
+	 *
+	 * @access private
+	 * @since 3.1.0
+	 *
+	 * @param string $primary_table
+	 * @param string $primary_id_column
+	 * @param string $meta_table
+	 * @param string $meta_id_column
+	 * @return array( $join_sql, $where_sql )
+	 */
+	function get_meta_sql( $primary_table, $primary_id_column, $meta_table, $meta_id_column ) {
+		global $wpdb;
+
+		$clauses = array();
+
+		$join = '';
+		$where = '';
+		$i = 0;
+		foreach ( $this->meta_query as $q ) {
+			$meta_key = isset( $q['key'] ) ? trim( $q['key'] ) : '';
+			$meta_value = isset( $q['value'] ) ? trim( $q['value'] ) : '';
+			$meta_compare = isset( $q['compare'] ) ? $q['compare'] : '=';
+
+			if ( !in_array( $meta_compare, array( '=', '!=', '>', '>=', '<', '<=', 'like' ) ) )
+				$meta_compare = '=';
+
+			if ( empty( $meta_key ) && empty( $meta_value ) )
+				continue;
+
+			$alias = $i ? 'mt' . $i : $meta_table;
+
+			$join .= "\nINNER JOIN $meta_table";
+			$join .= $i ? " AS $alias" : '';
+			$join .= " ON ($primary_table.$primary_id_column = $alias.$meta_id_column)";
+
+			$i++;
+
+			if ( !empty( $meta_key ) )
+				$where .= $wpdb->prepare( " AND $alias.meta_key = %s", $meta_key );
+
+			if ( empty( $meta_value ) )
+				continue;
+
+			if ( 'like' == $meta_compare ) {
+				$where .= $wpdb->prepare( " AND $alias.meta_value LIKE %s", '%' . like_escape( $meta_value ) . '%' );
+			} else {
+				$where .= $wpdb->prepare( " AND $alias.meta_value $meta_compare %s", $meta_value );
+			}
+		}
+
+		return array( $join, $where );
+	}
+}
+
+/**
  * WordPress Error class.
  *
  * Container for checking for WordPress errors and error messages. Return
