Answers.Body: <p>Yes, you can do that with <a href="https://craftcms.com/docs/4.x/matrix-blocks.html#querying-matrix-blocks" rel="nofollow noreferrer">matrix block queries</a>. Instead of going through entries to get the matrix blocks, you can query matrix blocks independently with a custom sort order.</p>
  <pre class="lang-twig prettyprint-override"><code>{% set notesByDate = craft.matrixBlocks()
      .type('note')
      .orderBy('note_date ASC')
      .all()
  %}
  </code></pre>
  <p>Replace <code>note</code> with the handle of the matrix block type of your notes and <code>note_date</code> with the handle of the date field.</p>
  <p>This will give you a list of matrix blocks. From the matrix blocks, you can get the owner entry using <a href="https://docs.craftcms.com/api/v4/craft-elements-matrixblock.html#method-getowner" rel="nofollow noreferrer">MatrixBlock::getOwner()</a>:</p>
  <pre class="lang-twig prettyprint-override"><code>{% for note in notesByDate %}
      Date: {{ note.date | date('medium') }}
      Note: {{ note.note }}
      Entry: {{ note.getOwner().title }}
  {% endfor %}
  </code></pre>
  <h2>Limiting matrix blocks to specific section</h2>
  <p>You can't limit a matrix block query to a specific section directly since they don't belong to a section. Matrix blocks are owned by entries and those entries belong to a section. So you need to limit the matrix query to matrix blocks that are <a href="https://craftcms.com/docs/4.x/matrix-blocks.html#ownerid" rel="nofollow noreferrer">owned by</a> the entries in that section:</p>
  <pre class="lang-twig prettyprint-override"><code>{% set entriesInSection = craft.entries().section('myCustomSection').ids() %}
  {% set notesByDateInCustomSection = craft.matrixBlocks()
      .type('note')
      .orderBy('note_date ASC')
      .ownerId(entriesInSection)
      .all()
  %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-06-29T14:28:01.583Z
Answers.Text: Brilliant - just what I needed. Thanks!
Answers.UserDisplayName: Ed Hebert
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-06-29T15:36:55.347Z
Answers.Text: While this got me 99% of the way there, I use this particular matrix block in several sections of the site. I want to filter the output to results from a particular section. I found that Matrix Blocks to not accept a .section() parameter. Any way to filter these matrixBlock results by section?
Answers.UserDisplayName: Ed Hebert
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-06-30T07:40:44.153Z
Answers.Text: @EdHebert I've added an example for limiting the query to a specific section!
Answers.UserDisplayName: MoritzLost
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-06-30T13:29:39.347Z
Answers.Text: thanks so much - worked!
Answers.UserDisplayName: Ed Hebert
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-06-29T13:34:32.520Z
Answers.LastActivityDate: 2022-06-30T07:38:26.003Z
Answers.LastEditDate: 2022-06-30T07:38:26.003Z
Answers.UserDisplayName: MoritzLost
Body: <p>I have a section with a matrix field that collects multiple notes for each entry, each marked by the date the note is entered. Conceptually, the data is organized within the entries as:</p>
  <pre><code>Entry A
       Jan 1     Note
       Mar 1     Note
  
  Entry B
       Feb 1     Note
       Apr 1     Note
  </code></pre>
  <p>I would like to extract all the notes from all the entries, and then display the collected information sorted by the dates the notes were entered, as in:</p>
  <pre><code>Jan 1    Note     Entry A
  Feb 1    Note     Entry B
  Mar 1    Note     Entry A
  Apr 1    Note     Entry B
  </code></pre>
  <p>Is this possible in Craft? I'm aware of the SuperSorter plugin, but am not sure whether what I am explaining is possible. If it is, I'm unclear about the syntax required to construct the query properly.</p>
  <p>Thanks</p>
  
Tags: <matrix><datetime><sorting><sort>
Title: Sorting all matrix fields from multiple entries as one list
ThreadText: # Sorting all matrix fields from multiple entries as one list
  
  (Asked by: username_0 on 2022-06-29)
  
  I have a section with a matrix field that collects multiple notes for each entry, each marked by the date the note is entered. Conceptually, the data is organized within the entries as:
  
  ```
  Entry A
       Jan 1     Note
       Mar 1     Note
  
  Entry B
       Feb 1     Note
       Apr 1     Note
  
  ```
  
  I would like to extract all the notes from all the entries, and then display the collected information sorted by the dates the notes were entered, as in:
  
  ```
  Jan 1    Note     Entry A
  Feb 1    Note     Entry B
  Mar 1    Note     Entry A
  Apr 1    Note     Entry B
  
  ```
  
  Is this possible in Craft? I'm aware of the SuperSorter plugin, but am not sure whether what I am explaining is possible. If it is, I'm unclear about the syntax required to construct the query properly.
  
  Thanks
  
  **Tags:** matrix, datetime, sorting, sort
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2022-06-29. Score: 3 | Accepted answer
  
  Yes, you can do that with [matrix block queries](https://craftcms.com/docs/4.x/matrix-blocks.html#querying-matrix-blocks). Instead of going through entries to get the matrix blocks, you can query matrix blocks independently with a custom sort order.
  
  ```twig
  {% set notesByDate = craft.matrixBlocks()
      .type('note')
      .orderBy('note_date ASC')
      .all()
  %}
  
  ```
  
  Replace `note` with the handle of the matrix block type of your notes and `note_date` with the handle of the date field.
  
  This will give you a list of matrix blocks. From the matrix blocks, you can get the owner entry using [MatrixBlock::getOwner()](https://docs.craftcms.com/api/v4/craft-elements-matrixblock.html#method-getowner):
  
  ```twig
  {% for note in notesByDate %}
      Date: {{ note.date | date('medium') }}
      Note: {{ note.note }}
      Entry: {{ note.getOwner().title }}
  {% endfor %}
  
  ```
  
  ## Limiting matrix blocks to specific section
  
  You can't limit a matrix block query to a specific section directly since they don't belong to a section. Matrix blocks are owned by entries and those entries belong to a section. So you need to limit the matrix query to matrix blocks that are [owned by](https://craftcms.com/docs/4.x/matrix-blocks.html#ownerid) the entries in that section:
  
  ```twig
  {% set entriesInSection = craft.entries().section('myCustomSection').ids() %}
  {% set notesByDateInCustomSection = craft.matrixBlocks()
      .type('note')
      .orderBy('note_date ASC')
      .ownerId(entriesInSection)
      .all()
  %}
  
  ```
  
  > **Comments:**
  > **username_0**: Brilliant - just what I needed. Thanks!  
  > **username_0**: While this got me 99% of the way there, I use this particular matrix block in several sections of the site. I want to filter the output to results from a particular section. I found that Matrix Blocks to not accept a .section() parameter. Any way to filter these matrixBlock results by section?  
  > **username_1**: @username_0 I've added an example for limiting the query to a specific section!  
  > **username_0**: thanks so much - worked!  
  
  ---
  
  