Answers.Body: <p>Update the query with the orderBy as well.</p>
  <pre><code>{% set entries = craft.entries()
  .search(searchQuery)
  .orderBy('postDate desc')
  .all() %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-10-04T07:01:34.187Z
Answers.Text: Thank you so much! I can confirm this worked.
Answers.UserDisplayName: michellelclement
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-09-28T06:18:43.100Z
Answers.LastActivityDate: 2023-03-03T01:15:50.383Z
Answers.LastEditDate: 2023-03-03T01:15:50.383Z
Answers.UserDisplayName: Prashant sharma
Body: <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>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2022-09-21T17:11:52.427Z
Comments.Text: 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).
Comments.UserDisplayName: Matt Stein
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2022-09-26T06:54:28.057Z
Comments.Text: 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?
Comments.UserDisplayName: michellelclement
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2022-09-26T16:48:10.733Z
Comments.Text: 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.
Comments.UserDisplayName: Matt Stein
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2022-10-04T07:02:24.550Z
Comments.Text: It appears you do! The results were displayed in date order, however, it wasn't sorting ALL the results into that order.
Comments.UserDisplayName: michellelclement
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2022-10-04T16:00:10.300Z
Comments.Text: Glad you figured it out! 
Comments.UserDisplayName: Matt Stein
Tags: <craft3><search>
Title: Structure entries not displaying in date order within search results
ThreadText: # 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 username_1, 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.  
  
  ---
  
  