Make WordPress Core

Opened 8 years ago

Closed 7 years ago

Last modified 7 years ago

#28589 closed defect (bug) (invalid)

Warning on Usage of WP_Query() with Orderby Array

Reported by: behrang Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.9.1
Component: Query Keywords: close
Focuses: Cc:

Description

When Using Orderby as array, like:

'orderby' => array(
        array(
            'meta_key' => 'ereignis-datum',
            'field' => 'meta_value_num',
            'order' => 'DESC'
        )
    )

your get

Warning: urldecode() expects parameter 1 to be string, array given in /subdomains/muenzenbergforum.de/htdocs/wp-includes/query.php on line 2634

Since several version i'm forced to make @urlencode to avoid having the warning on the page.

But with every update of course it comes back, since query.php is overwritten.

Change History (5)

#1 @engelen
8 years ago

  • Keywords close added
  • Resolution set to invalid
  • Status changed from new to closed

Welcome to the WordPress Core trac, and thanks for your report! This is not a bug in WordPress, however. orderby doesn't accept anything other than a string, so what you're trying to pass (an array) is actually not support by WP_Query. You should alter your orderby-parameter (by using orderby => 'meta_value_num', combined with the proper meta_key query parameter, for example).

Closing as invalid.

Last edited 8 years ago by engelen (previous) (diff)

#2 @SergeyBiryukov
8 years ago

  • Milestone Awaiting Review deleted

#3 follow-up: @steffenborup
7 years ago

  • Resolution invalid deleted
  • Status changed from closed to reopened

The codex does indicate that it is possible to pass an array to 'orderby', though:

Mulitiple orderby/order pairs
'orderby' => array( 'meta_value_num' => 'DESC', 'title' => 'ASC' ), 'meta_key' => 'age'

In the description of "Order & Orderby Parameters" the codex also states the following:

order (string | array) - Designates the ascending or descending order of the 'orderby' parameter. Defaults to 'DESC'. An array can be used for multiple order/orderby sets.

But when passing an array to 'order' I receive the following warning:

Warning: strtoupper() expects parameter 1 to be string, array given in

#4 in reply to: ↑ 3 @SergeyBiryukov
7 years ago

  • Resolution set to invalid
  • Status changed from reopened to closed

Replying to steffenborup:

The codex does indicate that it is possible to pass an array to 'orderby', though

This was added in 4.0, see [29027] and #17065. Looks like you're using 3.9.2.

#5 @johnbillion
7 years ago

It looks like somebody edited the Codex to reflect the upcoming changes in 4.0 even though it's not yet released. We should remind people not to do this.

Note: See TracTickets for help on using tickets.