#29716 closed defect (bug) (invalid)
orderby for meta values is broken in 4.0
Reported by: | 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)
#3
@
10 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
@
10 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' => '=' ) ), );
Note: See
TracTickets for help on using
tickets.
Did that work in a development version of 4.0? The structure to use is:
or the old style