WordPress.org

Make WordPress Core

Opened 5 years ago

Closed 5 years ago

#40157 closed defect (bug) (wontfix)

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

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

Description

A query like so:
https://highforthis.com/wp-json/wp/v2/media?include[]=2719&include[]=2724&include[]=2728

Returns the items in reverse order:
2728
2724
2719

include is the batch mechanism, it should order by post__in

Change History (2)

#1 @bor0
5 years ago

If you include orderby=include, it sorts them correctly: https://highforthis.com/wp-json/wp/v2/media?include[]=2719&include[]=2724&include[]=2728&orderby=include

Otherwise, the sort defaults to date.

#2 @jnylen0
5 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) {
  [0]=>
  int(5)
  [1]=>
  int(1)
}
wp> ( new WP_Query() )->query( array( 'post__in' => array( 5, 1 ), 'fields' => 'ids' ) )
=> array(2) {
  [0]=>
  int(5)
  [1]=>
  int(1)
}

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.