Craft CMS Stack Exchange is a question and answer site for administrators, end users, developers and designers for Craft CMS. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a page which lists assets by source. I've added a date field to the asset.

How can I order the assets by this field so that the most recent is first?

asset date field

Here is my markup:

{% set assets = craft.assets.find({sourceId: 2}) %}

{% for asset in assets %}
    <a href="{{ asset.url }}">{{ | date('M Y') }}</a>
{% endfor %}

Looking at the cheat sheet for Assets it seems that these are my only options for order: title, id, sourceId, folderId, filename, kind, width, height, size desc'.

Ideally I could do something like this:

{% set assets = craft.assets.find({sourceId: 2, order: '{{ }}'}) %}
share|improve this question
up vote 7 down vote accepted

You're so close it's maddening—you should be able to order by a custom field as well:

{% set assets = craft.assets.find({sourceId: 2, order: 'date desc'}) %}

Where date is the name of your custom field.

From the Craft docs (emphasis added):

Possible values include 'title', 'id', 'sourceId', 'folderId', 'filename', 'kind', 'width', 'height', 'size', 'dateCreated', and 'dateUpdated', as well as any textual custom field handles.

share|improve this answer
Thank you. I was so close. It works perfectly. I've also noted your edits on my post for future questions. – Niall Thompson Jul 14 '14 at 17:44
@NiallThompson Your question was excellent and thorough, I just did some tidying. I hope you don't mind :) – Matt Stein Jul 14 '14 at 17:46

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.