Automattic\WooCommerce\Internal\Admin\ProductReviews
ReviewsListTable::get_sort_arguments
Builds the orderby and order arguments based on the current request.
Method of the class: ReviewsListTable{}
No Hooks.
Returns
Array.
Usage
// protected - for code of main (parent) or child class $result = $this->get_sort_arguments() : array;
ReviewsListTable::get_sort_arguments() ReviewsListTable::get sort arguments code WC 10.3.6
protected function get_sort_arguments() : array {
$orderby = sanitize_text_field( wp_unslash( $_REQUEST['orderby'] ?? '' ) );
$order = sanitize_text_field( wp_unslash( $_REQUEST['order'] ?? '' ) );
$args = [];
if ( ! in_array( $orderby, $this->get_sortable_columns(), true ) ) {
$orderby = 'comment_date_gmt';
}
// If ordering by "rating", then we need to adjust to sort by meta value.
if ( 'rating' === $orderby ) {
$orderby = 'meta_value_num';
$args['meta_key'] = 'rating';
}
if ( ! in_array( strtolower( $order ), [ 'asc', 'desc' ], true ) ) {
$order = 'desc';
}
return wp_parse_args(
[
'orderby' => $orderby,
'order' => strtolower( $order ),
],
$args
);
}