[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 17:00:03 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:
--------------------------+-------------------------
Comment (by dariopad):
Replying to [comment:3 boonebgorges]:
> 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!
Wow! Now that I better understood what's the improvement was about, I can
state for sure there is no bug and your last example fits what I was
trying to reach out. I didn't realize I could also use a sub-clause in the
meta query. This is indeed the most powerful improvement in meta query
ever.
Really thank you for your precious support and I apologize if I didn't
catch the real meaning of the improvement.
I just suggest to better document this powerful improvement with some
extra example as you shared with me in this ticket.
Kr, Dario.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/32659#comment:4>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list