Answers.Body: <p><s>As far as I know, the only criteria to filter Matrix blocks is the <code>type</code> property or to pick a block by it's position with <code>first</code>, <code>last</code> or the new <code>nth</code> filter.</p>
  
  <p>Yes, it would totally make sense to have more options to grab select Matrix blocks and I am rather confident that this is s.th. that is already on "The List".</s></p>
  
  <p><strong>Update:</strong></p>
  
  <p>Craft 2.3 change things! Besides using the <code>type</code> property or to pick a block by it's position with <code>first</code>, <code>last</code> or the <code>nth</code> filter it is now possible to query for Matrix blocks using all sorts of custom field parameters.</p>
  
  <pre><code>{% set entry = craft.entries.slug('myMatrixEntry').first() %}
  
  {# Query Matrix blocks using custom field parameters #}
  {% set blocks = entry.myMatrixField.type('text').myLightswitchField('1').myDateField('&gt; 2014-12-02') %}
  
  {% for block in blocks %}
  ...
  {% endfor %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-09-04T13:00:58.693Z
Answers.LastActivityDate: 2014-12-03T15:40:58.163Z
Answers.LastEditDate: 2014-12-03T15:40:58.163Z
Answers.UserDisplayName: carlcs
Body: <p>So let's say I have the following code. I have the data to retrieve the entry I want, But I only want to return some of the matrix rows based on some criteria.</p>
  
  <p>Example Code:</p>
  
  <pre><code>{% set entryId = 1 %}
  {% set entry = craft.entries({ section: "mySection", id: entryId }).first() %}
  
  {% set myMatrixOutput = entry.myMatrixField.find({ someFieldInTheMatix: 2 }) %}
  
  {% for row in myMatrixOutput %}
      {{ row.someFieldInTheMatrix }}
  {% endfor %}
  </code></pre>
  
  <p>I can't get that to work it simply return me everything. I know that I could adjust my loop to be</p>
  
  <pre><code>{% for row in myMatrixOutput if row.someFieldInTheMatix == 2 %}
  </code></pre>
  
  <p>But say I have a large number of rows in the matrix field it would seem a waste to do all that looping if it could just bring back the correct results?</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2014-12-03T15:41:38.003Z
Comments.Text: You example code should work with Craft 2.3 :D
Comments.UserDisplayName: carlcs
Tags: <matrix><elementcriteriamodel>
Title: How can I return specific matrix rows based on criteria?
ThreadText: # How can I return specific matrix rows based on criteria?
  
  (Asked by: username_0 on 2014-09-03)
  
  So let's say I have the following code. I have the data to retrieve the entry I want, But I only want to return some of the matrix rows based on some criteria.
  
  Example Code:
  
  ```
  {% set entryId = 1 %}
  {% set entry = craft.entries({ section: "mySection", id: entryId }).first() %}
  
  {% set myMatrixOutput = entry.myMatrixField.find({ someFieldInTheMatix: 2 }) %}
  
  {% for row in myMatrixOutput %}
      {{ row.someFieldInTheMatrix }}
  {% endfor %}
  
  ```
  
  I can't get that to work it simply return me everything. I know that I could adjust my loop to be
  
  ```
  {% for row in myMatrixOutput if row.someFieldInTheMatix == 2 %}
  
  ```
  
  But say I have a large number of rows in the matrix field it would seem a waste to do all that looping if it could just bring back the correct results?
  
  **Tags:** matrix, elementcriteriamodel
  
  > **Comments:**
  > **username_1**: You example code should work with Craft 2.3 :D  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2014-09-04. Score: 3
  
  ~~As far as I know, the only criteria to filter Matrix blocks is the `type` property or to pick a block by it's position with `first`, `last` or the new `nth` filter.~~
  
  Yes, it would totally make sense to have more options to grab select Matrix blocks and I am rather confident that this is s.th. that is already on "The List".
  
  **Update:**
  
  Craft 2.3 change things! Besides using the `type` property or to pick a block by it's position with `first`, `last` or the `nth` filter it is now possible to query for Matrix blocks using all sorts of custom field parameters.
  
  ```
  {% set entry = craft.entries.slug('myMatrixEntry').first() %}
  
  {# Query Matrix blocks using custom field parameters #}
  {% set blocks = entry.myMatrixField.type('text').myLightswitchField('1').myDateField('> 2014-12-02') %}
  
  {% for block in blocks %}
  ...
  {% endfor %}
  
  ```
  
  
  ---
  
  