<p>Update the query with the orderBy as well.</p>
<pre><code>{% set entries = craft.entries()
.search(searchQuery)
.orderBy('postDate desc')
.all() %}
</code></pre>

CC BY-SA 4.0
2022-10-04T07:01:34.187Z
Thank you so much! I can confirm this worked.
michellelclement
CC BY-SA 4.0
2022-09-28T06:18:43.100Z
2023-03-03T01:15:50.383Z
2023-03-03T01:15:50.383Z
Prashant sharma
<p>I have created a search results page to display matching entries to a search term, ordered by the most recent.</p>
<p>The set-up works well for all entries which are not part of a structure. Results of entries within a structure appear at the end of the search results together and in reverse date order. Could this be that structure sections are searched separately from the rest of the site? The results are displaying, just not how they should.</p>
<p>I am working with legacy code and my knowledge of this feature is very limited.</p>
<p>Is anyone able to point me in the right direction for including entries from structures within the rest of the search results, and in date order?</p>
<p>Thank you!</p>
<pre><code>{% set searchQuery = craft.app.request.getParam('q') %}
{% set entries = craft.entries()
.search(searchQuery)
.all() %}
</code></pre>

CC BY-SA 4.0
2022-09-21T17:11:52.427Z
Welcome to the Craft CMS Stack Exchange, @michellelclement! Is that example the actual element query you’re using? I’m not seeing date-ordering or [specific sort methods](https://craftcms.com/docs/3.x/searching.html#ordering-results-by-score).
Matt Stein
CC BY-SA 4.0
2022-09-26T06:54:28.057Z
Hi Matt, Thanks for your reply! Yes, that is the actual query. The results are automatically sorted by the most recent entries first. However, do you think I need to add the specific sorting method for the structure elements to be included in the same result ordering?
michellelclement
CC BY-SA 4.0
2022-09-26T16:48:10.733Z
I don’t know if you _should_ have to specify the sort order, I’m just wondering if it makes any difference. Even if not, detailing whatever you’ve tried could be useful context.
Matt Stein
CC BY-SA 4.0
2022-10-04T07:02:24.550Z
It appears you do! The results were displayed in date order, however, it wasn't sorting ALL the results into that order.
michellelclement
CC BY-SA 4.0
2022-10-04T16:00:10.300Z
Glad you figured it out! 
Matt Stein
<craft3><search>
Structure entries not displaying in date order within search results
# Structure entries not displaying in date order within search results

(Asked by: username_0 on 2022-09-21)

I have created a search results page to display matching entries to a search term, ordered by the most recent.
The set-up works well for all entries which are not part of a structure. Results of entries within a structure appear at the end of the search results together and in reverse date order. Could this be that structure sections are searched separately from the rest of the site? The results are displaying, just not how they should.
I am working with legacy code and my knowledge of this feature is very limited.
Is anyone able to point me in the right direction for including entries from structures within the rest of the search results, and in date order?
Thank you!
{% set searchQuery = craft.app.request.getParam('q') %}
{% set entries = craft.entries()
.search(searchQuery)
.all() %}

**Tags:** craft3, search

> **Comments:**
> **username_1**: Welcome to the Craft CMS Stack Exchange, @username_0! Is that example the actual element query you’re using? I’m not seeing date-ordering or [specific sort methods](https://craftcms.com/docs/3.x/searching.html#ordering-results-by-score).  
> **username_0**: Hi Matt, Thanks for your reply! Yes, that is the actual query. The results are automatically sorted by the most recent entries first. However, do you think I need to add the specific sorting method for the structure elements to be included in the same result ordering?  
> **username_1**: I don’t know if you _should_ have to specify the sort order, I’m just wondering if it makes any difference. Even if not, detailing whatever you’ve tried could be useful context.  
> **username_0**: It appears you do! The results were displayed in date order, however, it wasn't sorting ALL the results into that order.  
> **username_1**: Glad you figured it out!   

---

## 1 answers

### Answer by username_2 on 2022-09-28. Score: 2

Update the query with the orderBy as well.
{% set entries = craft.entries()
.search(searchQuery)
.orderBy('postDate desc')
.all() %}

> **Comments:**
> **username_0**: Thank you so much! I can confirm this worked.  

---

