Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

sorting product with more than one key

sorting product with more than one key

luxehouze_dev
Shopify Partner
4 0 0

When using the Storefront API (ver 2024-07), is it possible to sort products within a collection based on multiple `sortKeys`, such as `PRICE` and `CREATED`?

Replies 3 (3)

Eric-HAN
Shopify Partner
213 26 22

Hi,there

I guess this is not directly supported. The API allows sorting by a single  sortKey  at a time.

For collections, you can use the sortKey parameter with values from the ProductCollectionSortKeys enum, which includes options like PRICE and CREATED, but not a combination of both.Then  do another sorting in your logic by program

- Helpful? Please hit Like and mark it as a solution
Want to modify or custom changes on store? Let me help.
- Feel free to Email Me    Buy Me A Coffee
luxehouze_dev
Shopify Partner
4 0 0

Hi, thank you for your reply. I was curious about how pagination works when we implement custom sorting in our program. How do we handle the cursor for the next page or previous page?

Eric-HAN
Shopify Partner
213 26 22

You could refer to this https://shopify.dev/docs/api/usage/pagination-graphql

- Helpful? Please hit Like and mark it as a solution
Want to modify or custom changes on store? Let me help.
- Feel free to Email Me    Buy Me A Coffee