Make WordPress Core

Opened 11 years ago

Closed 11 years ago

Last modified 11 years ago

#29716 closed defect (bug) (invalid)

orderby for meta values is broken in 4.0

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

Description

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

is not working anymore.

Change History (7)

#1 @kitchin
11 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',
Last edited 11 years ago by kitchin (previous) (diff)

#2 @SergeyBiryukov
11 years ago

  • Component changed from General to Query

#3 @johnbillion
11 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to invalid
  • Status changed from new to closed

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

#4 @devarni
11 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 11 years ago by devarni (previous) (diff)

#5 follow-up: @kitchin
11 years ago

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

#6 in reply to: ↑ 5 @devarni
11 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
11 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.