Add support for sorting by includes param.

This commit is contained in:
Vedanshu Jain 2022-12-28 15:44:56 +05:30
parent 2712b4724f
commit d00f606849
1 changed files with 17 additions and 1 deletions

View File

@ -509,8 +509,17 @@ class OrdersTableQuery {
return;
}
// No need to sanitize, will be processed in calling function.
if ( 'include' === $orderby || 'post__in' === $orderby ) {
return;
}
if ( is_string( $orderby ) ) {
$orderby = array( $orderby => $order );
$orderby_fields = array_map( 'trim', explode( ' ', $orderby ) );
$orderby = array();
foreach ( $orderby_fields as $field ) {
$orderby[ $field ] = $order;
}
}
$this->args['orderby'] = array();
@ -977,6 +986,13 @@ class OrdersTableQuery {
return;
}
if ( 'include' === $orderby || 'post__in' === $orderby ) {
$ids = $this->args['id'];
$ids = array_map( 'absint', $ids );
$this->orderby = array( "FIELD( {$this->tables['orders']}.id, " . implode( ',', $ids ) . ' )' );
return;
}
$orderby_array = array();
foreach ( $this->args['orderby'] as $_orderby => $order ) {
$orderby_array[] = "{$_orderby} {$order}";