<p>What I'm not clear of is if you are asking if you can query for entries that have a matrix field that contains x, or if you just asking if you can search within a matrix field of an entry that has already been returned by a query. </p>

<p>If it is the later, the following solution would work. This isn't a feature of Craft, but a feature of Twig. Thus, implementing it won't save on queries or anything, but it will help you filter the results returned by Craft.</p>

<p>Twig has a feature that allows you to apply a condition in addition to the for loop. It is documented <a href="http://twig.sensiolabs.org/doc/tags/for.html#adding-a-condition" rel="nofollow">here</a>.</p>

<pre><code>{% for cta in entry.homeCtas if cta.ctaTitle == "Lorem Ipsum" %}
    &lt;h1&gt;{{ cta.ctaTitle }}&lt;/h1&gt;
{% endfor %}
</code></pre>

CC BY-SA 3.0
2014-08-25T02:11:20.497Z
Thanks, Wes. I should have clarified this further. I _was_ working with the latter situation. I'll give this a shot!
Aaron Bushnell
CC BY-SA 3.0
2014-08-25T00:48:58.700Z
2014-08-25T00:48:58.700Z
Wes Rice
<p>I'm not entirely sure how to search a <em>specific</em> Matrix field for a given bit of content. I can use:</p>

<pre><code>{% for cta in entry.homeCtas.search('"Lorem Ipsum"') %}
    &lt;h1&gt;{{ cta.ctaTitle }}&lt;/h1&gt;
{% endfor %}
</code></pre>

<p>to find any Matrix rows with "Lorem Ipsum" (not in a specific field). But when I try something like this:</p>

<pre><code>{% for cta in entry.homeCtas.search('ctaTitle:"Lorem Ipsum"') %}
    &lt;h1&gt;{{ cta.ctaTitle }}&lt;/h1&gt;
{% endfor %}
</code></pre>

<p>It returns nothing. Is my field syntax incorrect? Am I missing something obvious?</p>

CC BY-SA 3.0
2014-08-24T22:12:47.363Z
I think this could help: http://craftcms.stackexchange.com/a/2104/125
carlcs
CC BY-SA 3.0
2014-08-24T22:26:42.020Z
Hm, I'm not certain that confirms/denies an ability to search a specific field within a Matrix, though. The comment at the end ("You can't use search('fileId:sitelogo'), because that would filter for entries with fileId:sitelogo and not entries with a matrix block fileId:sitelogo.") makes it sound like this user is explaining why the author's original code doesn't work. I don't see anything about if it's possible or not.
Aaron Bushnell
CC BY-SA 3.0
2014-08-24T22:33:51.290Z
There is no such thing as a matrixcriteriamodel. Only type and limit filter is possible (at least that's the only filters documented).
carlcs
CC BY-SA 3.0
2014-08-25T07:31:24.890Z
This didn't help, Aaron?
carlcs
CC BY-SA 3.0
2014-08-25T17:30:58.147Z
Sorry, carlcs. Thanks for clarifying that for me! Hopefully one day Matrix will have this level of support.
Aaron Bushnell
<matrix><search><filter>
How to search for content in a specific Matrix field?
# How to search for content in a specific Matrix field?

(Asked by: username_0 on 2014-08-24)

I'm not entirely sure how to search a specific Matrix field for a given bit of content. I can use:
{% for cta in entry.homeCtas.search('"Lorem Ipsum"') %}
    {{ cta.ctaTitle }}
{% endfor %}

to find any Matrix rows with "Lorem Ipsum" (not in a specific field). But when I try something like this:
{% for cta in entry.homeCtas.search('ctaTitle:"Lorem Ipsum"') %}
    {{ cta.ctaTitle }}
{% endfor %}

It returns nothing. Is my field syntax incorrect? Am I missing something obvious?

**Tags:** matrix, search, filter
> **Comments:**
> **username_1**: I think this could help: http://craftcms.stackexchange.com/a/2104/125  
> **username_0**: Hm, I'm not certain that confirms/denies an ability to search a specific field within a Matrix, though. The comment at the end ("You can't use search('fileId:sitelogo'), because that would filter for entries with fileId:sitelogo and not entries with a matrix block fileId:sitelogo.") makes it sound like this user is explaining why the author's original code doesn't work. I don't see anything about if it's possible or not.  
> **username_1**: There is no such thing as a matrixcriteriamodel. Only type and limit filter is possible (at least that's the only filters documented).  
> **username_1**: This didn't help, Aaron?  
> **username_0**: Sorry, carlcs. Thanks for clarifying that for me! Hopefully one day Matrix will have this level of support.  

---

## 1 answers

### Answer by username_2 on 2014-08-25. Score: 2 | Accepted answer

What I'm not clear of is if you are asking if you can query for entries that have a matrix field that contains x, or if you just asking if you can search within a matrix field of an entry that has already been returned by a query. 
If it is the later, the following solution would work. This isn't a feature of Craft, but a feature of Twig. Thus, implementing it won't save on queries or anything, but it will help you filter the results returned by Craft.
Twig has a feature that allows you to apply a condition in addition to the for loop. It is documented here.
{% for cta in entry.homeCtas if cta.ctaTitle == "Lorem Ipsum" %}
    {{ cta.ctaTitle }}
{% endfor %}

> **Comments:**
> **username_0**: Thanks, Wes. I should have clarified this further. I _was_ working with the latter situation. I'll give this a shot!  

---

