Order by Multiple Fields in Craft CMS

By Chandra McFarlen

Back to latest posts

Today, I was trying to figure out how to do something new (for me) in Craft CMS: How to order a list of entries by more than one custom field.

The documentation (for the order parameter) didn't explicitly state how to do this, so I did a quick search on their stackexchange. (Note: I actually use Google to search their stackexchange because this usually gives better results IMHO.) I usually find the answers I need there, but this time no quick luck.

So, as I have done several times in working with Craft CMS, I thought to myself, "Well, what would be the most logical / obvious solution." And, Walla!

{% for entry in craft.entries.section('sectionHandle').order('field1').order('field2').order('field3') %}
{{ entry.title }}
{% endfor %}

All you have to do is continue adding .order parameters. So, in the above example, the entries would be ordered by custom field1 followed by custom field2 and then custom field3. My particular custom fields were all Number field types.

blog comments powered by Disqus