PHPackages                             topshelfcraft/supersort - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. topshelfcraft/supersort

ActiveCraft-plugin[Utility &amp; Helpers](/categories/utility)

topshelfcraft/supersort
=======================

...a super-duper sorting function for your Craft templates.

5.1.0(6d ago)4188.1k↓50%2[3 issues](https://github.com/TopShelfCraft/SuperSort/issues)1proprietaryPHP

Since Dec 24Pushed 6d ago2 watchersCompare

[ Source](https://github.com/TopShelfCraft/SuperSort)[ Packagist](https://packagist.org/packages/topshelfcraft/supersort)[ RSS](/packages/topshelfcraft-supersort/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependencies (4)Versions (9)Used By (1)

SuperSort
=========

[](#supersort)

*...a super-duper sorting function for your Craft CMS templates.*

**A [Top Shelf Craft](https://topshelfcraft.com) creation**
[Michael Rog](https://michaelrog.com), Proprietor

---

What is SuperSort?
------------------

[](#what-is-supersort)

The **SuperSort** plugin provides a powerful Twig filter that helps with ordering an array of values — either using one of PHP's built-in methods to sort the actual values, or using custom "sort as" methods to arrange the array based on the rendered results of processing each member as a Twig object template.

Using **SuperSort**'s "sort as" methods, you can sort an array of elements by any accessible object value — including values from Matrix blocks, attributes of related elements, math calculations, etc.

Usage
-----

[](#usage)

### Installation

[](#installation)

Visit the *Plugin Store* in your Craft control panel, search for **SuperSort**, and click to *Install* the plugin.

Or, if you're feeling frisky, you can install **SuperSort** via [Composer](https://getcomposer.org/):

```
composer require topshelfcraft/supersort

```

### General usage

[](#general-usage)

Use the `supersort` filter to sort an array of objects.

(You can apply `supersort` to any array or *ElementQuery*. A non-array-like source will be converted into a single-item array... which probably isn't very useful for sorting.)

### Basic Sorting

[](#basic-sorting)

The first parameter of the filter specifies the sort method.

```
{% set sortedSource = source | supersort('asort') %}

```

You can use any of [PHP's built-in sort methods](http://php.net/manual/en/array.sorting.php):

- [`'asort'`](http://php.net/manual/en/function.asort.php)
- [`'arsort'`](http://php.net/manual/en/function.arsort.php)
- [`'ksort'`](http://php.net/manual/en/function.ksort.php)
- [`'krsort'`](http://php.net/manual/en/function.krsort.php)
- [`'natsort'`](http://php.net/manual/en/function.natsort.php)
- [`'natcasesort'`](http://php.net/manual/en/function.natcasesort.php)
- [`'sort'`](http://php.net/manual/en/function.sort.php)
- [`'rsort'`](http://php.net/manual/en/function.rsort.php)
- [`'shuffle'`](http://php.net/manual/en/function.shuffle.php)

If you don't supply this first parameter, a plain vanilla `asort` will be applied:

```
{% set sortedSource = source | supersort %}

```

In many common cases — such as when you're sorting names, numbers, or filenames — the default `'asort'` algorithm may produce unwanted results. In those cases, consider using the case-insensitive natural sorting algorithm ([`'natcasesort'`](http://php.net/manual/en/function.natcasesort.php)).

### Advanced ("As") Sorting

[](#advanced-as-sorting)

You can also sort by one of **SuperSort**'s custom methods:

- `'sortAs'`
- `'rsortAs'`
- `'natsortAs'`
- `'natcasesortAs'`

To use these methods, you will provide a second parameter, which is a Twig object template to [render](https://docs.craftcms.com/api/v3/craft-web-view.html#renderObjectTemplate()-detail) using each object in the array:

```
{% set upcomingEvents = upcomingEvents | supersort('sortAs', '{eventDates.first.date}') %}

{% set upcomingEvents = upcomingEvents | supersort('sortAs', '{{ object.eventDates.first.date }}') %}

```

(This "object template" syntax is the same as you might use to define a [Dynamic Subfolder Path](http://buildwithcraft.com/docs/assets-fields#dynamic-subfolder-paths) for an Assets field.

### Sort Flags

[](#sort-flags)

You can optionally provide a third parameter — one of PHP's [sort flags](http://php.net/manual/en/function.sort.php).

```
{% set source = source | supersort('sortAs', '{foo}', SORT_NUMERIC) %}

{% set source = source | supersort('asort', null, SORT_NUMERIC) %}

```

If you don't supply this third parameter, the default (`SORT_REGULAR`) flag is used.

### Custom-Order Sorting via Archetype

[](#custom-order-sorting-via-archetype)

The custom-order methods sort an array by custom order provided in an archetype.

- `'customOrderSort'`
- `'customOrderKsort'`

To use these methods, you will provide an archetype (exemplar) list via the `comp` parameter:

```
{% set upcomingEvents = upcomingEvents | supersort('customOrderSort', comp: ['Value1', 'Value2']) %}

{% set upcomingEvents = upcomingEvents | supersort('customOrderKsort', comp: ['key1', 'key2']) %}

```

Items which do not appear in the archetype list appear at end of the list, in their original relative order.

### Using SuperSort as a PHP helper

[](#using-supersort-as-a-php-helper)

If you'd like to use the `superSort()` method as a helper in another Craft plugin or component, you can access it in PHP directly from the Sorter service:

```
$result = Sorter::superSort($array, $method, $as, $sortFlag, $comp);
```

(Note: [PHP's built-in sort methods](http://php.net/manual/en/array.sorting.php) sort an array in place and return a *boolean* representing success. The `superSort()` method, by contrast, returns the result *array*.)

---

Support
-------

[](#support)

### What are the system requirements?

[](#what-are-the-system-requirements)

Craft 5.0+ and PHP 8.0+

### I found a bug.

[](#i-found-a-bug)

Nah...

### I triple-checked. It's a bug.

[](#i-triple-checked-its-a-bug)

Well, alright. Please open a GitHub Issue, or submit a PR to the `5.x.dev` branch.

---

#### Contributors:

[](#contributors)

- Plugin development: [Michael Rog](https://michaelrog.com) / @michaelrog
- Craft 3 port: [TJ Draper](https://buzzingpixel.com) / @tjdraperpro
- Icon: [Ralf Schmitzer](https://dribbble.com/schmitzer), via [The Noun Project](https://thenounproject.com/term/sort/503379)

###  Health Score

59

—

FairBetter than 98% of packages

Maintenance98

Actively maintained with recent releases

Popularity40

Moderate usage in the ecosystem

Community15

Small or concentrated contributor base

Maturity68

Established project with proven stability

 Bus Factor1

Top contributor holds 89.5% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~777 days

Total

5

Last Release

6d ago

Major Versions

3.1.0 → 4.0.02022-05-16

4.0.0 → 5.0.02024-07-28

### Community

Maintainers

![](https://www.gravatar.com/avatar/7fabbca3f39380eadb6f89517be9a0fbc550159a1eec925452da43d14338de66?d=identicon)[TopShelfCraft](/maintainers/TopShelfCraft)

---

Top Contributors

[![michaelrog](https://avatars.githubusercontent.com/u/102379?v=4)](https://github.com/michaelrog "michaelrog (17 commits)")[![tjdraper](https://avatars.githubusercontent.com/u/3803475?v=4)](https://github.com/tjdraper "tjdraper (1 commits)")[![tvd0x2a](https://avatars.githubusercontent.com/u/89363871?v=4)](https://github.com/tvd0x2a "tvd0x2a (1 commits)")

---

Tags

arraysortlistcmsCraftcraftcmscraft-pluginsortingSuperSort

### Embed Badge

![Health badge](/badges/topshelfcraft-supersort/health.svg)

```
[![Health](https://phpackages.com/badges/topshelfcraft-supersort/health.svg)](https://phpackages.com/packages/topshelfcraft-supersort)
```

###  Alternatives

[verbb/formie

The most user-friendly forms plugin for Craft.

102393.6k70](/packages/verbb-formie)[verbb/comments

Add comments to your site.

13753.9k](/packages/verbb-comments)[verbb/navigation

Create navigation menus for your site.

92705.0k18](/packages/verbb-navigation)[verbb/vizy

A flexible visual editor field for Craft.

4250.4k](/packages/verbb-vizy)[verbb/hyper

A user-friendly links field for Craft.

24147.8k12](/packages/verbb-hyper)[topshelfcraft/wordsmith

...because you have the best words.

30349.8k7](/packages/topshelfcraft-wordsmith)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
