Forum

Thread tagged as: Problem, Shop

perch_shop_products sort by price

I am trying to sort my products by price highest to lowest:

perch_shop_products([
    'category' => 'products/flowers',
    'sort' => 'price',
    'sort-order' => 'DESC',
]);

But there is nothing showing up. If I get rid of the sort options then it will render but in no specific order.

If I var_dump the data, I can see that the price is actually an array, I guess its supposed to hold a price per currency.

["price"]=>
    array(1) {
      [44]=>
      string(5) "70.00"
    }

I figure I have to sort by price[44] or something like that but I cant figure it out.

Andrew Wallace

Andrew Wallace 0 points

  • 4 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

price is indexed as the basic price in the default currency, so that's fine to sort by. It's not an array - the index can't store arrays.

Have you tried adding a trailing slash to the category slug?

Also you might want to try adding:

'sort-type' => 'numeric',

Thanks, I hadn't set the default currency so once I set that I then had to go through each product and save it to update the index and its all working sweet now :)