sortByField for Craft CMS
Adds a "sortByField" Twig filter which sorts an array of entries by the specified field's value.
- Move the
sortbyfield
directory into yourcraft/plugins
directory. - 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') %}