Make WordPress Core

Ticket #39055: 39055.diff

File 39055.diff, 631 bytes (added by sanket.parmar, 8 years ago)

I think we need to sort the post__in array based on order. I mean if order is desc then we have to sort post__in in reverse order and when order is asc, we have to sort post__in in normal order. So if include=5,2,1&orderby=include or include=5,2,1&orderby=include&order=desc is passed then result should be [ { id: 5...}, { id: 2...}, { id: 1... } ] and when include=5,2,1&orderby=include&order=asc is passed then result should be [ { id: 1...}, { id: 2...}, { id: 5... } ]. Let me know if it is correct.

  • src/wp-includes/class-wp-query.php

     
    19541954                if ( $q['p'] ) {
    19551955                        $where .= " AND {$wpdb->posts}.ID = " . $q['p'];
    19561956                } elseif ( $q['post__in'] ) {
     1957                        if ( 'desc' === $q['order'] ) {
     1958                                arsort( $q['post__in'] );
     1959                        } else {
     1960                                asort( $q['post__in'] );
     1961                        }
     1962                       
    19571963                        $post__in = implode(',', array_map( 'absint', $q['post__in'] ));
    19581964                        $where .= " AND {$wpdb->posts}.ID IN ($post__in)";
    19591965                } elseif ( $q['post__not_in'] ) {