<pre><code>{% set entries = craft.entries.orderBy('foo').all() %}
</code></pre>

<p>There is an <code>orderBy</code> property you can use on the query </p>

CC BY-SA 4.0
2018-06-28T05:18:12.463Z
2018-06-28T05:18:12.463Z
Robin Schambach
<p>I want to order my search results by the post date (not the created on date).  And, this did not work...</p>

<pre><code>{% if entries|length %}
    {% for post in entries.groupBy('postDate') %}
        {% include 'partials/card-standard-4' %}
    {% endfor %}                            
{% else %}
    &lt;p&gt;Your search for “{{ query }}” didn’t return any results.&lt;/p&gt;
{% endif %}
</code></pre>

<templating>
How can I order search results by the post date?
# How can I order search results by the post date?

(Asked by: username_0 on 2018-06-27)

I want to order my search results by the post date (not the created on date).  And, this did not work...
{% if entries|length %}
    {% for post in entries.groupBy('postDate') %}
        {% include 'partials/card-standard-4' %}
    {% endfor %}                            
{% else %}
    Your search for “{{ query }}” didn’t return any results.
{% endif %}

**Tags:** templating

---

## 1 answers

### Answer by username_1 on 2018-06-28. Score: 1 | Accepted answer

{% set entries = craft.entries.orderBy('foo').all() %}

There is an orderBy property you can use on the query


---

