sortByField for Craft CMS
Adds a "sortByField" Twig filter which sorts an array of entries by the specified field's value.
Please note this filter is no longer needed with the latest version of Craft CMS, the functionality is included by default.
- Move the
sortbyfielddirectory into yourcraft/pluginsdirectory. - Go to Settings > Plugins from your Craft control panel and enable the sortByField plugin.
{% for entry in craft.entries|sortByField('height') %}
The filter also accepts an optional direction parameter:
{% for entry in craft.entries|sortByField('weight', 'desc') %}