
Filter values sorting
Controlling the order in which filter values are displayed.
Sorting levels
Filter value sorting is configured at two levels:
- Filter configuration (in the filter set) — JSON settings
- mFilterForm snippet parameters — override for output
Default order
By default values are sorted by product count (DESC) — most popular first.
Settings in filter configuration
In the admin mFilter → Filter sets you can set sort parameters for each filter:
{
"color": {
"type": "default",
"source": "option",
"field": "color",
"label": "Color",
"sort": "value",
"sort_dir": "asc"
}
}Sort parameters
| Parameter | Description | Values |
|---|---|---|
sort | Sort field | count (default), value |
sort_dir | Direction | desc (default), asc |
selected_first | Selected at top | true, false |
pinned | Pinned values | Array of values |
custom_order | Full custom order | Array of values |
Configuration examples
Alphabetical (A–Z)
{
"brand": {
"type": "default",
"source": "option",
"label": "Brand",
"sort": "value",
"sort_dir": "asc"
}
}Alphabetical (Z–A)
{
"brand": {
"type": "default",
"source": "option",
"label": "Brand",
"sort": "value",
"sort_dir": "desc"
}
}By product count (high → low)
{
"color": {
"type": "default",
"source": "option",
"label": "Color",
"sort": "count",
"sort_dir": "desc"
}
}By product count (low → high)
{
"color": {
"type": "default",
"source": "option",
"label": "Color",
"sort": "count",
"sort_dir": "asc"
}
}Selected values at top
Values selected by the user move to the top of the list:
{
"size": {
"type": "default",
"source": "option",
"label": "Size",
"sort": "value",
"sort_dir": "asc",
"selected_first": true
}
}Pinned values
Certain values stay at the top; the rest are sorted normally:
{
"brand": {
"type": "default",
"source": "option",
"label": "Brand",
"pinned": ["Apple", "Samsung", "Xiaomi"],
"sort": "count",
"sort_dir": "desc"
}
}Result:
- Apple
- Samsung
- Xiaomi
- (others by count descending)
Fully custom order
Explicit order for all values:
{
"size": {
"type": "default",
"source": "option",
"label": "Size",
"custom_order": ["XS", "S", "M", "L", "XL", "XXL"]
}
}Values not listed in custom_order are appended at the end.
mFilterForm snippet parameters
sortByCount
Overrides sorting — values with more products go to the top:
{'!mFilterForm' | snippet: [
'resourceId' => $_modx->resource.id,
'sortByCount' => 1
]}Priority
The sortByCount snippet parameter is applied after the filter configuration sort and overrides it.
hideZero
Hides values with zero product count:
{'!mFilterForm' | snippet: [
'resourceId' => $_modx->resource.id,
'hideZero' => 1
]}Default hideZero = true.
Combining settings
Brands: popular + alphabetical
{
"brand": {
"type": "default",
"source": "option",
"label": "Brand",
"pinned": ["Apple", "Samsung"],
"sort": "value",
"sort_dir": "asc"
}
}Result:
- Apple (pinned)
- Samsung (pinned)
- ASUS (alphabetical)
- Dell (alphabetical)
- HP (alphabetical)
- ...
Sizes: custom order + selected at top
{
"size": {
"type": "default",
"source": "option",
"label": "Size",
"custom_order": ["XS", "S", "M", "L", "XL", "XXL"],
"selected_first": true
}
}Application order
Sorting is applied in this order:
- custom_order — if set, defines the full order
- sort + sort_dir — standard sort (when no custom_order)
- selected_first — selected values move to top
- pinned — pinned values move to the start
- sortByCount (snippet) — final re-sort by count
Natural sort
For the value field natural sort (strnatcasecmp) is used, so numbers in strings sort correctly:
- Regular:
1, 10, 2, 20, 3 - Natural:
1, 2, 3, 10, 20
This matters for sizes (e.g. S, M, L, XL) and numeric values in strings.
Examples for different filter types
Colors — by popularity
{
"color": {
"type": "colors",
"source": "option",
"label": "Color",
"sort": "count",
"sort_dir": "desc"
}
}Vendors — alphabetical with top 3 pinned
{
"vendor": {
"type": "vendors",
"source": "ms3",
"label": "Vendor",
"pinned": ["Apple", "Samsung", "Sony"],
"sort": "value",
"sort_dir": "asc"
}
}Years — newest to oldest
{
"year": {
"type": "year",
"source": "field",
"field": "publishedon",
"label": "Year",
"sort": "value",
"sort_dir": "desc"
}
}Clothing sizes — custom order
{
"size": {
"type": "default",
"source": "option",
"field": "size",
"label": "Size",
"custom_order": ["XXS", "XS", "S", "M", "L", "XL", "XXL", "XXXL"]
}
}