Make WordPress Core

Opened 12 years ago

Closed 12 years ago

Last modified 12 years ago

#29716 closed defect (bug) (invalid)

orderby for meta values is broken in 4.0

Reported by: devarni Owned by:
Priority: normal Milestone:
Component: Query Version: 4.0
Severity: normal Keywords: reporter-feedback
Cc: Focuses:

Description

'orderby' => array(array('meta_key' => 'date', 'order' => 'DESC'))

is not working anymore.

Change History (7)

#1 @kitchin
12 years ago

  • Keywords reporter-feedback added

Did that work in a development version of 4.0? The structure to use is:

'meta_key' => 'date',
'orderby' => array('meta_value' => 'DESC'),

or the old style

'meta_key' => 'date',
'orderby' => 'meta_value'.
'order' => 'DESC',
Version 0, edited 12 years ago by kitchin (next)

#2 @SergeyBiryukov
12 years ago

  • Component GeneralQuery

#3 @johnbillion
12 years ago

  • Milestone Awaiting Review
  • Resolutioninvalid
  • Status newclosed

Thanks for the report, devarni, but this is indeed an invalid format. Either of kitchin's suggested formats will do the trick.

#4 @devarni
12 years ago

I think it has something to do with the meta_query... this breaks the order for unknown reasons in combination with the OR relation. This behavior is new with 4.0. Removing the meta_query ordering is working as expected.

This is the example query:
If the meta key "is_private" or does not exist or if the value is empty the post should be queried.
This is not working with 4.0 anymore and the same time the orderby is not working correctly.

$query_vars = array(
            'post_type' => DG_POST_SLUG,
            'meta_key' => DG_PREFIX . 'date',
            'orderby'  => array('meta_value_num' => 'DESC'),
            'posts_per_page' => $posts_per_page,
            'paged' => $page_no,
            'meta_query' => array(
                'relation' => 'OR',
                array(
                    'key' => DG_PREFIX . 'is_private',
                    'compare' => 'NOT EXISTS',
                ),
                array(
                    'key' => DG_PREFIX . 'is_private',
                    'value' => '',
                    'type' => 'CHAR',
                    'compare' => '='
                )
            ),
        );
Last edited 12 years ago by devarni (previous) (diff)

#5 follow-up: @kitchin
12 years ago

That's different. What was your query in 3.9 ?

#6 in reply to: ↑ 5 @devarni
12 years ago

Replying to kitchin:

That's different. What was your query in 3.9 ?

It was the same query in 3.9
Besides the ordering thing, the OR relation is not working in 4.0 and the private records are returned!

#7 @kitchin
12 years ago

But 'orderby' was not an array in 3.9. Was that the query you had in 3.9? It's easier if you paste in the old query than describe it.

Note: See TracTickets for help on using tickets.