<p>You can query Matrix blocks like you are used to with all other elements</p>

<pre><code>{% set blocks = element.matrixFieldHandle.type('typeHandle').field('some value').all() %}
</code></pre>

<p>Keep in mind your <code>field</code> should be a valid field handle within your block type </p>

CC BY-SA 4.0
2018-06-08T18:39:58.143Z
I'm trying to get all entries with given field value, not all blocks.
Камен Великов
CC BY-SA 4.0
2018-06-08T18:42:50.757Z
You can either use the search parameter or do something like this https://craftcms.stackexchange.com/questions/26447/element-query-matrixfields-where
Robin Schambach
CC BY-SA 4.0
2018-06-08T18:58:54.473Z
What do you mean by search parameter?
Камен Великов
CC BY-SA 4.0
2018-06-08T19:00:51.670Z
https://docs.craftcms.com/v2/searching.html but you need to leave the field parameter blank - > you'll get all results with the search term not just the results for a certain field. Another method would be to filter for matrixBlocks directly and get their owner. It's easier but resource heavy https://github.com/craftcms/cms/blob/develop/src/web/twig/variables/CraftVariable.php#L288 `set blocks = craft.matrixBlocks.typeId(x).fieldHandle(value). all()` then loop the result and query their owner
Robin Schambach
CC BY-SA 4.0
2018-06-08T19:14:57.843Z
Or even better `entryIds = craft.matrixBlocks...... select('ownerId').column()` and then filter for those ids
Robin Schambach
CC BY-SA 4.0
2018-05-20T08:38:38.247Z
2018-05-20T08:51:51.330Z
2018-05-20T08:51:51.330Z
Robin Schambach
<p>I have a Matrix field and I want to be able to filter by it.</p>

<p>For example I want to get all entries that has <code>matrixField.field1Type.value = {some value}.</code></p>

<p>How can I do that?</p>

<matrix>
How can I filter by Matrix field
# How can I filter by Matrix field

(Asked by: username_0 on 2018-05-20)

I have a Matrix field and I want to be able to filter by it.

For example I want to get all entries that has `matrixField.field1Type.value = {some value}.`

How can I do that?

**Tags:** matrix

---

## 1 answers

### Answer by username_1 on 2018-05-20. Score: 1

You can query Matrix blocks like you are used to with all other elements
{% set blocks = element.matrixFieldHandle.type('typeHandle').field('some value').all() %}

Keep in mind your field should be a valid field handle within your block type

> **Comments:**
> **username_0**: I'm trying to get all entries with given field value, not all blocks.  
> **username_1**: You can either use the search parameter or do something like this https://craftcms.stackexchange.com/questions/26447/element-query-matrixfields-where  
> **username_0**: What do you mean by search parameter?  
> **username_1**: https://docs.craftcms.com/v2/searching.html but you need to leave the field parameter blank - > you'll get all results with the search term not just the results for a certain field. Another method would be to filter for matrixBlocks directly and get their owner. It's easier but resource heavy https://github.com/craftcms/cms/blob/develop/src/web/twig/variables/CraftVariable.php#L288 `set blocks = craft.matrixBlocks.typeId(x).fieldHandle(value). all()` then loop the result and query their owner  
> **username_1**: Or even better `entryIds = craft.matrixBlocks...... select('ownerId').column()` and then filter for those ids  

---

