<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[31340] trunk: Modify `meta_query orderby syntax to use array keys as clause "handles".</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="https://core.trac.wordpress.org/changeset/31340">31340</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"https://core.trac.wordpress.org/changeset/31340","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>boonebgorges</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2015-02-05 19:37:47 +0000 (Thu, 05 Feb 2015)</dd>
</dl>
<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>Modify `meta_query orderby syntax to use array keys as clause "handles".
The implementation of `meta_query` orderby introduced in <a href="https://core.trac.wordpress.org/changeset/31312">[31312]</a> put clause
identifiers into a 'name' parameter of the clause. For greater clarity, this
changeset updates the syntax to use the associative array key used when
defining `meta_query` parameters, instead of the 'name' parameter.
Props Funkatronic, DrewAPicture.
Fixes <a href="https://core.trac.wordpress.org/ticket/31045">#31045</a>.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpincludesmetaphp">trunk/src/wp-includes/meta.php</a></li>
<li><a href="#trunksrcwpincludesqueryphp">trunk/src/wp-includes/query.php</a></li>
<li><a href="#trunktestsphpunittestsquerymetaQueryphp">trunk/tests/phpunit/tests/query/metaQuery.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcwpincludesmetaphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/meta.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/meta.php 2015-02-05 19:18:16 UTC (rev 31339)
+++ trunk/src/wp-includes/meta.php 2015-02-05 19:37:47 UTC (rev 31340)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -945,12 +945,13 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * Constructor.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 3.2.0
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @since 4.2.0 Introduced the `$name` parameter, for improved `$orderby` support in the parent query.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @since 4.2.0 Introduced support for naming query clauses by associative array keys.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @access public
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @param array $meta_query {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * Array of meta query clauses.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Array of meta query clauses. When first-order clauses use strings as their array keys, they may be
+ * referenced in the 'orderby' parameter of the parent query.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @type string $relation Optional. The MySQL keyword used to join
</span><span class="cx" style="display: block; padding: 0 10px"> * the clauses of the query. Accepts 'AND', or 'OR'. Default 'AND'.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -967,8 +968,6 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * comparisons. Accepts 'NUMERIC', 'BINARY', 'CHAR', 'DATE',
</span><span class="cx" style="display: block; padding: 0 10px"> * 'DATETIME', 'DECIMAL', 'SIGNED', 'TIME', or 'UNSIGNED'.
</span><span class="cx" style="display: block; padding: 0 10px"> * Default is 'CHAR'.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @type string $name Optional. A unique identifier for the clause. If provided, `$name` can be
- * referenced in the `$orderby` parameter of the parent query.
</del><span class="cx" style="display: block; padding: 0 10px"> * }
</span><span class="cx" style="display: block; padding: 0 10px"> * }
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1016,14 +1015,14 @@
</span><span class="cx" style="display: block; padding: 0 10px"> unset( $query['value'] );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $clean_queries[] = $query;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $clean_queries[ $key ] = $query;
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Otherwise, it's a nested query, so we recurse.
</span><span class="cx" style="display: block; padding: 0 10px"> } else {
</span><span class="cx" style="display: block; padding: 0 10px"> $cleaned_query = $this->sanitize_query( $query );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> if ( ! empty( $cleaned_query ) ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $clean_queries[] = $cleaned_query;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $clean_queries[ $key ] = $cleaned_query;
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1270,7 +1269,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // This is a first-order clause.
</span><span class="cx" style="display: block; padding: 0 10px"> if ( $this->is_first_order_clause( $clause ) ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $clause_sql = $this->get_sql_for_clause( $clause, $query );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $clause_sql = $this->get_sql_for_clause( $clause, $query, $key );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $where_count = count( $clause_sql['where'] );
</span><span class="cx" style="display: block; padding: 0 10px"> if ( ! $where_count ) {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1321,8 +1320,10 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 4.1.0
</span><span class="cx" style="display: block; padding: 0 10px"> * @access public
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param array $clause Query clause, passed by reference.
- * @param array $parent_query Parent query array.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param array $clause Query clause, passed by reference.
+ * @param array $parent_query Parent query array.
+ * @param string $clause_key Optional. The array key used to name the clause in the original `$meta_query`
+ * parameters. If not provided, a key will be generated automatically.
</ins><span class="cx" style="display: block; padding: 0 10px"> * @return array {
</span><span class="cx" style="display: block; padding: 0 10px"> * Array containing JOIN and WHERE SQL clauses to append to a first-order query.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1330,7 +1331,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @type string $where SQL fragment to append to the main WHERE clause.
</span><span class="cx" style="display: block; padding: 0 10px"> * }
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- public function get_sql_for_clause( &$clause, $parent_query ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ public function get_sql_for_clause( &$clause, $parent_query, $clause_key = '' ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> global $wpdb;
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $sql_chunks = array(
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1391,9 +1392,21 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $meta_type = $this->get_cast_for_type( $_meta_type );
</span><span class="cx" style="display: block; padding: 0 10px"> $clause['cast'] = $meta_type;
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // Fallback for clause keys is the table alias.
+ if ( ! $clause_key ) {
+ $clause_key = $clause['alias'];
+ }
+
+ // Ensure unique clause keys, so none are overwritten.
+ $iterator = 1;
+ $clause_key_base = $clause_key;
+ while ( isset( $this->clauses[ $clause_key ] ) ) {
+ $clause_key = $clause_key_base . '-' . $iterator;
+ $iterator++;
+ }
+
</ins><span class="cx" style="display: block; padding: 0 10px"> // Store the clause in our flat array.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $clause_name = isset( $clause['name'] ) ? $clause['name'] : $clause['alias'];
- $this->clauses[ $clause_name ] =& $clause;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $this->clauses[ $clause_key ] =& $clause;
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Next, build the WHERE clause.
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1471,7 +1484,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * Get a flattened list of sanitized meta clauses, indexed by clause 'name'.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Get a flattened list of sanitized meta clauses.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * This array should be used for clause lookup, as when the table alias and CAST type must be determined for
</span><span class="cx" style="display: block; padding: 0 10px"> * a value of 'orderby' corresponding to a meta clause.
</span></span></pre></div>
<a id="trunksrcwpincludesqueryphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/query.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/query.php 2015-02-05 19:18:16 UTC (rev 31339)
+++ trunk/src/wp-includes/query.php 2015-02-05 19:37:47 UTC (rev 31340)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1450,6 +1450,8 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * Parse a query string and set query type booleans.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 1.5.0
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @since 4.2.0 Introduced the ability to order by specific clauses of a `$meta_query`, by passing the clause's
+ * array key to `$orderby`.
</ins><span class="cx" style="display: block; padding: 0 10px"> * @access public
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @param string|array $query {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1497,11 +1499,14 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @type int $offset The number of posts to offset before retrieval.
</span><span class="cx" style="display: block; padding: 0 10px"> * @type string $order Designates ascending or descending order of posts. Default 'DESC'.
</span><span class="cx" style="display: block; padding: 0 10px"> * Accepts 'ASC', 'DESC'.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @type string $orderby Sort retrieved posts by parameter. One or more options can be
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @type string|array $orderby Sort retrieved posts by parameter. One or more options may be
</ins><span class="cx" style="display: block; padding: 0 10px"> * passed. To use 'meta_value', or 'meta_value_num',
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * 'meta_key=keyname' must be also be defined. Default 'date'.
- * Accepts 'none', 'name', 'author', 'date', 'title', 'modified',
- * 'menu_order', 'parent', 'ID', 'rand', 'comment_count'.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * 'meta_key=keyname' must be also be defined. To sort by a
+ * specific `$meta_query` clause, use that clause's array key.
+ * Default 'date'. Accepts 'none', 'name', 'author', 'date',
+ * 'title', 'modified', 'menu_order', 'parent', 'ID', 'rand',
+ * 'comment_count', 'meta_value', 'meta_value_num', and the
+ * array keys of `$meta_query`.
</ins><span class="cx" style="display: block; padding: 0 10px"> * @type int $p Post ID.
</span><span class="cx" style="display: block; padding: 0 10px"> * @type int $page Show the number of posts that would show up on page X of a
</span><span class="cx" style="display: block; padding: 0 10px"> * static front page.
</span></span></pre></div>
<a id="trunktestsphpunittestsquerymetaQueryphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/query/metaQuery.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/query/metaQuery.php 2015-02-05 19:18:16 UTC (rev 31339)
+++ trunk/tests/phpunit/tests/query/metaQuery.php 2015-02-05 19:37:47 UTC (rev 31340)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1562,7 +1562,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * @ticket 31045
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- public function test_orderby_name() {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ public function test_orderby_clause_key() {
</ins><span class="cx" style="display: block; padding: 0 10px"> $posts = $this->factory->post->create_many( 3 );
</span><span class="cx" style="display: block; padding: 0 10px"> add_post_meta( $posts[0], 'foo', 'aaa' );
</span><span class="cx" style="display: block; padding: 0 10px"> add_post_meta( $posts[1], 'foo', 'zzz' );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1571,13 +1571,12 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $q = new WP_Query( array(
</span><span class="cx" style="display: block; padding: 0 10px"> 'fields' => 'ids',
</span><span class="cx" style="display: block; padding: 0 10px"> 'meta_query' => array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- array(
- 'name' => 'foo_name',
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'foo_key' => array(
</ins><span class="cx" style="display: block; padding: 0 10px"> 'key' => 'foo',
</span><span class="cx" style="display: block; padding: 0 10px"> 'compare' => 'EXISTS',
</span><span class="cx" style="display: block; padding: 0 10px"> ),
</span><span class="cx" style="display: block; padding: 0 10px"> ),
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'orderby' => 'foo_name',
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'orderby' => 'foo_key',
</ins><span class="cx" style="display: block; padding: 0 10px"> 'order' => 'DESC',
</span><span class="cx" style="display: block; padding: 0 10px"> ) );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1587,7 +1586,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * @ticket 31045
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- public function test_orderby_name_as_secondary_sort() {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ public function test_orderby_clause_key_as_secondary_sort() {
</ins><span class="cx" style="display: block; padding: 0 10px"> $p1 = $this->factory->post->create( array(
</span><span class="cx" style="display: block; padding: 0 10px"> 'post_date' => '2015-01-28 03:00:00',
</span><span class="cx" style="display: block; padding: 0 10px"> ) );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1605,15 +1604,14 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $q = new WP_Query( array(
</span><span class="cx" style="display: block; padding: 0 10px"> 'fields' => 'ids',
</span><span class="cx" style="display: block; padding: 0 10px"> 'meta_query' => array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- array(
- 'name' => 'foo_name',
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'foo_key' => array(
</ins><span class="cx" style="display: block; padding: 0 10px"> 'key' => 'foo',
</span><span class="cx" style="display: block; padding: 0 10px"> 'compare' => 'EXISTS',
</span><span class="cx" style="display: block; padding: 0 10px"> ),
</span><span class="cx" style="display: block; padding: 0 10px"> ),
</span><span class="cx" style="display: block; padding: 0 10px"> 'orderby' => array(
</span><span class="cx" style="display: block; padding: 0 10px"> 'post_date' => 'asc',
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'foo_name' => 'asc',
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'foo_key' => 'asc',
</ins><span class="cx" style="display: block; padding: 0 10px"> ),
</span><span class="cx" style="display: block; padding: 0 10px"> ) );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1623,7 +1621,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * @ticket 31045
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- public function test_orderby_more_than_one_name() {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ public function test_orderby_more_than_one_clause_key() {
</ins><span class="cx" style="display: block; padding: 0 10px"> $posts = $this->factory->post->create_many( 3 );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> add_post_meta( $posts[0], 'foo', 'jjj' );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1636,23 +1634,50 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $q = new WP_Query( array(
</span><span class="cx" style="display: block; padding: 0 10px"> 'fields' => 'ids',
</span><span class="cx" style="display: block; padding: 0 10px"> 'meta_query' => array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- array(
- 'name' => 'foo_name',
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'foo_key' => array(
</ins><span class="cx" style="display: block; padding: 0 10px"> 'key' => 'foo',
</span><span class="cx" style="display: block; padding: 0 10px"> 'compare' => 'EXISTS',
</span><span class="cx" style="display: block; padding: 0 10px"> ),
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- array(
- 'name' => 'bar_name',
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'bar_key' => array(
</ins><span class="cx" style="display: block; padding: 0 10px"> 'key' => 'bar',
</span><span class="cx" style="display: block; padding: 0 10px"> 'compare' => 'EXISTS',
</span><span class="cx" style="display: block; padding: 0 10px"> ),
</span><span class="cx" style="display: block; padding: 0 10px"> ),
</span><span class="cx" style="display: block; padding: 0 10px"> 'orderby' => array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'foo_name' => 'asc',
- 'bar_name' => 'desc',
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'foo_key' => 'asc',
+ 'bar_key' => 'desc',
</ins><span class="cx" style="display: block; padding: 0 10px"> ),
</span><span class="cx" style="display: block; padding: 0 10px"> ) );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertEquals( array( $posts[2], $posts[0], $posts[1] ), $q->posts );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+ /**
+ * @ticket 31045
+ */
+ public function test_duplicate_clause_keys_should_be_made_unique() {
+ $q = new WP_Query( array(
+ 'fields' => 'ids',
+ 'meta_query' => array(
+ 'foo_key' => array(
+ 'key' => 'foo',
+ 'compare' => 'EXISTS',
+ ),
+ array(
+ 'foo_key' => array(
+ 'key' => 'bar',
+ 'compare' => 'EXISTS',
+ ),
+ ),
+ array(
+ 'foo_key' => array(
+ 'key' => 'baz',
+ 'compare' => 'EXISTS',
+ ),
+ ),
+ ),
+ ) );
+
+ $this->assertEqualSets( array( 'foo_key', 'foo_key-1', 'foo_key-2' ), array_keys( $q->meta_query->get_clauses() ) );
+ }
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span></span></pre>
</div>
</div>
</body>
</html>