From abef04de830171a324802462087a2d7c36bb8f8c Mon Sep 17 00:00:00 2001 From: Clay Griffiths Date: Fri, 23 Sep 2022 13:03:15 -0500 Subject: [PATCH] Fixed issue where ordering results did not work. --- class-object-type-google-sheet.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/class-object-type-google-sheet.php b/class-object-type-google-sheet.php index 03e0640..1ea7c12 100644 --- a/class-object-type-google-sheet.php +++ b/class-object-type-google-sheet.php @@ -322,6 +322,7 @@ public function query( $args ) { * @var $primary_property_value * @var $property * @var $property_id + * @var $ordering */ extract( $args ); @@ -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 );