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.0.0(1y ago)4287.1k↓16.7%2[3 issues](https://github.com/TopShelfCraft/SuperSort/issues)1proprietaryPHP

Since Dec 24Pushed 1y ago2 watchersCompare

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

READMEChangelogDependencies (2)Versions (8)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.

### 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 4.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 `4.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

43

—

FairBetter than 91% of packages

Maintenance32

Infrequent updates — may be unmaintained

Popularity40

Moderate usage in the ecosystem

Community14

Small or concentrated contributor base

Maturity68

Established project with proven stability

 Bus Factor1

Top contributor holds 93.8% 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 ~802 days

Total

4

Last Release

651d 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 (15 commits)")[![tjdraper](https://avatars.githubusercontent.com/u/3803475?v=4)](https://github.com/tjdraper "tjdraper (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/navigation

Create navigation menus for your site.

90683.7k17](/packages/verbb-navigation)[verbb/formie

The most user-friendly forms plugin for Craft.

101372.9k40](/packages/verbb-formie)[verbb/comments

Add comments to your site.

13753.1k](/packages/verbb-comments)[verbb/tablemaker

Create customizable and user-defined table fields.

40168.8k1](/packages/verbb-tablemaker)[supercool/tablemaker

Create customizable and user-defined table fields.

40141.7k](/packages/supercool-tablemaker)[pennebaker/craft-architect

CraftCMS plugin to generate content models from JSON/YAML data.

72148.5k5](/packages/pennebaker-craft-architect)

PHPackages © 2026

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