<p>I assume, that title is a subfield of a matrix field, because title is a reserved name in craft. So as far as I understand your Question, you want to get some results out of a matrix field thats in one of your pages ('pageOne', 'pageTwo', 'pageThree'). That means you have to loop over this field as well. </p>

<pre><code>{% if entries|length %}
   {% for entry in entries %}
       {% for block in entry.matrixFieldHandle %}
          &lt;a href="{{ entry.url }}"&gt;{{ entry.title }} - {{ block.matrixTitle }}&lt;/a&gt;
       {% endfor %}
   {% endfor %}
{% endif %}
</code></pre>

CC BY-SA 3.0
2018-02-08T09:49:36.350Z
Perfect! Thank you
Amy
CC BY-SA 3.0
2018-02-08T09:51:49.763Z
Your Welcome. I just realized, that title is also forbidden inside a matrix field, so i changed the handle inside the block to 'pageName' ;)
Laslo89
CC BY-SA 3.0
2018-02-08T09:52:57.263Z
What you had was perfect, {{ block.title }} was what gave me the field title. just needed both {{ entry.title }} - {{ block.title }} for page name and field name :)
Amy
CC BY-SA 3.0
2018-02-08T10:28:32.573Z
@Amy I'm just curious: how were you able to insert `title` as a field handle in your craft matrix field? `title` is a reserved keyword it's usually not possible to use it as a handle
Robin Schambach
CC BY-SA 3.0
2018-02-08T10:32:37.333Z
The section I was looking to search through was a Q&A section, so my title was {{ entry.question }}. You are right, you cannot use just 'title', bad example on my part
Amy
CC BY-SA 3.0
2018-02-08T09:43:34.147Z
2018-02-09T07:05:45.260Z
2018-02-09T07:05:45.260Z
Laslo89
<p>I'm trying to create somewhat of a clever search for which only searches through certain pages of my site. At the moment, it can search those pages, but instead of the result returning the page name, I want it to return a field within the matrix field which the search query can be found in.</p>
<p>As an example below, if a user were to search for <em><strong>Lorem Ipsum</strong></em>, I want it to return the page name as well as the matrix field title.</p>
<blockquote>
<p><strong>This is my title</strong></p>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s.</p>
</blockquote>
<p>Desired result:</p>
<blockquote>
<p>Page Name: This is my title</p>
</blockquote>
<p>So far, the code I have can be found here, but I'm unsure how to access to exact matrix field title and add it to the query.</p>
<pre><code>{% set query = craft.request.getParam('q') %}
{% set entries = craft.entries.search(query).order('score').section(['pageOne', 'pageTwo', 'pageThree']) %}

{% if entries|length %}
    {% for entry in entries %}
        &lt;a href=&quot;{{ entry.url }}&quot;&gt;{{ entry.title }}&lt;/a&gt;
    {% endfor %}
{% endif %}
</code></pre>
<p>Is this possible to achieve?</p>

<matrix><search><field><query>
Search and link to Entries Matrix Field
# Search and link to Entries Matrix Field

(Asked by: username_0 on 2018-02-08)

I'm trying to create somewhat of a clever search for which only searches through certain pages of my site. At the moment, it can search those pages, but instead of the result returning the page name, I want it to return a field within the matrix field which the search query can be found in.
As an example below, if a user were to search for Lorem Ipsum, I want it to return the page name as well as the matrix field title.

This is my title
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s.

Desired result:

Page Name: This is my title

So far, the code I have can be found here, but I'm unsure how to access to exact matrix field title and add it to the query.
{% set query = craft.request.getParam('q') %}
{% set entries = craft.entries.search(query).order('score').section(['pageOne', 'pageTwo', 'pageThree']) %}

{% if entries|length %}
    {% for entry in entries %}
        {{ entry.title }}
    {% endfor %}
{% endif %}

Is this possible to achieve?

**Tags:** matrix, search, field, query


---

## 1 answers

### Answer by username_1 on 2018-02-08. Score: 2 | Accepted answer

I assume, that title is a subfield of a matrix field, because title is a reserved name in craft. So as far as I understand your Question, you want to get some results out of a matrix field thats in one of your pages ('pageOne', 'pageTwo', 'pageThree'). That means you have to loop over this field as well. 
{% if entries|length %}
   {% for entry in entries %}
       {% for block in entry.matrixFieldHandle %}
          {{ entry.title }} - {{ block.matrixTitle }}
       {% endfor %}
   {% endfor %}
{% endif %}

> **Comments:**
> **username_0**: Perfect! Thank you  
> **username_1**: Your Welcome. I just realized, that title is also forbidden inside a matrix field, so i changed the handle inside the block to 'pageName' ;)  
> **username_0**: What you had was perfect, {{ block.title }} was what gave me the field title. just needed both {{ entry.title }} - {{ block.title }} for page name and field name :)  
> **username_2**: @username_0 I'm just curious: how were you able to insert `title` as a field handle in your craft matrix field? `title` is a reserved keyword it's usually not possible to use it as a handle  
> **username_0**: The section I was looking to search through was a Q&A section, so my title was {{ entry.question }}. You are right, you cannot use just 'title', bad example on my part  

---

