Order Assets by date field 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?



Here is my markup:

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

{% for asset in assets %}
    &lt;a href="{{ asset.url }}"&gt;{{ asset.date | date('M Y') }}&lt;/a&gt;
{% 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: '{{ asset.date }}'}) %}
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.