I am trying to sort my products by rating in a wp_query loop using this code but not able to do so
switch($ordering){
case 'default':
$meta_key = '';
$order = 'asc';
$orderby = 'menu_order title';
break;
case 'popularity':
$meta_key = '';
$order = 'desc';
$orderby = 'total_sales';
break;
case 'low_to_high':
$meta_key = '_price';
$order = 'asc';
$orderby = 'meta_value_num';
break;
case 'high_to_low':
$meta_key = '_price';
$order = 'desc';
$orderby = 'meta_value_num';
break;
case 'newness':
$meta_key = '';
$order = 'desc';
$orderby = 'date';
break;
case 'rating':
$meta_key = '';
$order = 'desc';
$orderby = 'rating';
break;
}
$args_products_sorting = array(
'post_type' => 'product',
'posts_per_page' => -1,
'orderby' => $orderby,
'order' => $order,
'meta_key' => $meta_key
);