Skip to content

Commit

Permalink
Fixed issue where ordering results did not work.
Browse files Browse the repository at this point in the history
  • Loading branch information
claygriffiths committed Sep 23, 2022
1 parent bc6d133 commit abef04d
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions class-object-type-google-sheet.php
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ public function query( $args ) {
* @var $primary_property_value
* @var $property
* @var $property_id
* @var $ordering
*/
extract( $args );

Expand All @@ -334,6 +335,17 @@ public function query( $args ) {
} );
}

$orderby = rgar( $ordering, 'orderby' );
$order = strtolower( rgar( $ordering, 'order', 'ASC' ) );

if ( ! empty( $orderby ) && count( $results ) && array_key_exists( $orderby, $results[0] ) ) {
if ( $order === 'rand' ) {
shuffle( $results );
} else {
array_multisort( array_column( $results, $orderby ), $order === 'desc' ? SORT_DESC : SORT_ASC, $results );
}
}

$query_limit = gp_populate_anything()->get_query_limit( $this, $args['field'] );
$query_results = array_slice( $results, 0, $query_limit );

Expand Down

0 comments on commit abef04d

Please sign in to comment.