Documentation Index
Fetch the complete documentation index at: https://docs.uselayers.com/llms.txt
Use this file to discover all available pages before exploring further.
Overview
Layers sort order metaobjects describe the sort options configured in your dashboard — their display name, code, and which surfaces they apply to. To render a working sort dropdown, combine the two data sources:- Read sort order metaobjects in Liquid to get the configured sorts and their codes.
- Filter by
scope(collectionorsearch) so each surface only shows the relevant options. - Pass the selected
codeto the Browse API or Search API assort_order_code.
Prerequisites
- The Layers Shopify app installed and synced.
- Sort orders configured in the Layers dashboard with Enable as Storefront Sort turned on.
- A storefront access token (available via
shop.metafields.layers.embed_settings). See Liquid integration for full setup.
Collection sort dropdown
Read and filter sort metaobjects in Liquid
Each sort metaobject exposes
name, code, scope (an array like ['collection', 'search']), and order (display priority). Filter by scope so collection pages only render collection sorts, then order by the configured order field.Also read the collection’s default sort from the layers.default_sort_order metafield — used to pre-select the dropdown when no sort query param is present.Pass the selected code to the Browse API
When the dropdown changes, request the new page from the Browse API with the selected
sort_order_code. Omit the field to fall back to the collection’s default sort order.Search sort dropdown
The pattern is identical — filter by thesearch scope and pass sort_order_code to the Search API execute endpoint instead.
Default sort orders
Default sorts are resolved on the server whensort_order_code is omitted:
| Surface | Default source |
|---|---|
| Collection | layers.default_sort_order metafield on the collection, falling back to the store default |
| Search | Relevance |
Available fields
| Field | Type | Description |
|---|---|---|
name | string | Display label |
code | string | Sort order code passed as sort_order_code |
scope | array | Surfaces where the sort is available: collection, search |
order | integer | Display order — lower numbers appear first |
Preserving sort across navigation
To keep the active sort sticky across pagination, filtering, and back/forward navigation:- Mirror the selection to the URL (
?sort=<code>) on change. - Read
request.params.sortin Liquid on the initial render so the right option isselectedserver-side. - Include
sort_order_codein every subsequent API call (Browse, Facets, applied-filter refreshes) until the user changes it.
Troubleshooting
Sort options are missing from the dropdown. Confirm Enable as Storefront Sort is turned on for the sort order in the Layers dashboard, and that the metaobject is visible under Content → Metaobjects in Shopify admin. A sort renders on the wrong surface. Check the sort’sscope array in the dashboard — collection-only sorts should not include search and vice versa.
The default sort doesn’t match the dashboard. Verify a default is assigned on the collection (Shopify admin → Products → Collections → [Collection] → Metafields → layers.default_sort_order) and that the referenced sort still exists in Layers.
See also
- Liquid integration — reading metaobjects from Liquid
- Rendering facets in Liquid — companion guide for filter sidebars
- Browse API — collection results with sorting
- Search API — full-text search with sorting
- Sort Orders — configuring sort orders in the Layers dashboard