[wp-trac] [WordPress Trac] #32659: Orderby meta clause in meta_query not working in 4.2.2
WordPress Trac
noreply at wordpress.org
Tue Jun 16 14:23:14 UTC 2015
#32659: Orderby meta clause in meta_query not working in 4.2.2
--------------------------+-------------------------
Reporter: dariopad | Owner:
Type: defect (bug) | Status: closed
Priority: normal | Milestone:
Component: Query | Version: 4.2.2
Severity: normal | Resolution: worksforme
Keywords: | Focuses:
--------------------------+-------------------------
Changes (by boonebgorges):
* status: new => closed
* focuses: administration, performance =>
* resolution: => worksforme
* milestone: Awaiting Review =>
Comment:
Replying to [comment:2 dariopad]:
> Now that you pointed out this example I realize that I really
misunderstood the use of this improvement. :(
> I realize now that this improvement relates to a way to reference a key
in the meta_query and include it to the orderby clause. Is that what the
improvement means?
> So as per your example, the only clause that should work on my previous
example would be the 'another_key' clause as it reference a single
meta_key?
As your query is written? Yes, 'another_clause' is the only one that will
work. However, you could do this:
{{{
$args = array ( [...],
'meta_query' => array(
'relation' => 'OR'
'my_clause' => array(
'my_subclause_1' => array( 'key' => 'any_key', 'compare' =>
'=', 'value' => '1', 'type' => 'CHAR')
'my_subclause_2' => array( 'key' => 'another_key',
'compare' => '=', 'value' => '1', 'type' => 'CHAR')
),
'another_clause' => array(
array( 'key' => 'any_other_key', 'compare' => '=', 'value'
=> '1', 'type' => 'CHAR')
)
),
'orderby' => array('my_subclause_1'=>'DESC', 'post_date'=>'DESC')
);
}}}
and that should order by the "my_subclause_1" table. (However, note that
because you're querying for value=1 in all cases, there'll always be a
tie, which means it'll always fall back to `post_date`. Clause-specific
'orderby' works best if you aren't using `'compare' => '='`.)
It sounds to me like this is all probably working as intended. If you have
suggestions for how to improve the documentation, or if you think there is
indeed a bug, please feel free to reopen the ticket. Thanks!
--
Ticket URL: <https://core.trac.wordpress.org/ticket/32659#comment:3>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list