Make WordPress Core

Opened 7 years ago

Closed 7 years ago

#40157 closed defect (bug) (wontfix)

Batch query for media returns items in DESC order instead of post__in

Reported by: wonderboymusic's profile wonderboymusic Owned by:
Milestone: Priority: normal
Severity: normal Version: 4.7
Component: REST API Keywords: needs-patch
Focuses: Cc:


A query like so:[]=2719&include[]=2724&include[]=2728

Returns the items in reverse order:

include is the batch mechanism, it should order by post__in

Change History (2)

#1 @bor0
7 years ago

If you include orderby=include, it sorts them correctly:[]=2719&include[]=2724&include[]=2728&orderby=include

Otherwise, the sort defaults to date.

#2 @jnylen0
7 years ago

  • Milestone 4.7.4 deleted
  • Resolution set to wontfix
  • Status changed from new to closed

From Slack discussion, this is working as intended.

Explicit is better than implicit

I agree with this - the order should not change based on the query parameters.

if include is an arg, shouldn’t orderby be include by default? that’s how post__in works internally

I'm seeing different behavior:

wp> ( new WP_Query() )->query( array( 'post__in' => array( 1, 5 ), 'fields' => 'ids' ) )
=> array(2) {
wp> ( new WP_Query() )->query( array( 'post__in' => array( 5, 1 ), 'fields' => 'ids' ) )
=> array(2) {

I agree with this also:

If you mean other uses of WP_Query, matching the behaviour of that is not a design goal

Note: See TracTickets for help on using tickets.