<p>Relations won't work here because they only apply to elements (Entries, Categories, Assets, etc). Instead, you can use the field handle to filter by field values depending on the field's type. See, for instance, the documentation of <a href="https://craftcms.com/docs/3.x/dropdown-fields.html" rel="nofollow noreferrer">Dropdown Fields</a> to find out how to filter them. In this case, your approach is correct in principle, you can pass a string that matches the value of one of the dropdown options to search for entries with that option selected.</p>
<p>So this should work:</p>
<pre><code>{% set relatedPeople = craft.entries()
    .section('people')
    .peopleGroup('cricket')
    .all()
%}
</code></pre>
<blockquote>
<p>I get - Impossible to invoke a method (&quot;peopleGroup&quot;) on an array.</p>
</blockquote>
<p>This is just a minor error, the problem is that you're trying to add a condition <em>after you've already executed the query</em> using <code>.all()</code>. The <code>.all()</code> method returns an array of results, so trying to call a method on that array will result in an error.</p>
<p>If you can't add all conditions in a single expression as I did above - for example, because some conditions are only added in specific situations - make sure only to execute <code>.all()</code> after all conditions have been added. Something like this:</p>
<pre><code>{# Create a query (craft\elements\db\EntryQuery). #}
{% set relatedPeopleQuery = craft.entries().section('people') %}

{# Add more conditions to the query. #}
{% do relatedPeopleQuery.peopleGroup('cricket') %}

{# Execute the query and fetch the results. #}
{% set relatedPeople = relatedPeopleQuery.all() %}
</code></pre>

CC BY-SA 4.0
2021-09-13T09:01:12.653Z
Thanks for the detailed answer, it works great. I have an understanding of how Craft CMS works in regards to the issue. It makes sense now.
smudge18
CC BY-SA 4.0
2021-09-13T12:05:42.443Z
@smudge18 Glad I could help! Would you mind marking my answer as accepted then? Thanks!
MoritzLost
CC BY-SA 4.0
2021-09-14T18:57:46.223Z
All done.. thanks for your help!
smudge18
CC BY-SA 4.0
2021-09-11T13:42:55.080Z
2021-09-11T13:42:55.080Z
MoritzLost
<p>I have a channel called 'people' where a dropdown is used to say if they like 'cricket' or 'football'</p>
<p>Inside a matrix related entry I am trying to show what they like from that dropdown field value inside a block for 'cricket' and block for 'football'</p>
<pre><code>{% set relatedPeople = craft.entries.section('people').relatedTo(block).all() %}
</code></pre>
<p>This gets the channel but I am struggling to then filter by the dropdown value, I thought I could use relatedTo but that's not for dropdown values.</p>
<p>I tried this on the group I created for the dropdown</p>
<pre><code>relatedPeople.peopleGroup('cricket')) 
</code></pre>
<p>I get:</p>
<blockquote>
<p>Impossible to invoke a method (&quot;peopleGroup&quot;) on an array.</p>
</blockquote>
<p>Any help would be grateful</p>

<craft3>
Filter a channel entry by dropdown value inside a matrix related filed
# Filter a channel entry by dropdown value inside a matrix related filed

(Asked by: username_0 on 2021-09-11)

I have a channel called 'people' where a dropdown is used to say if they like 'cricket' or 'football'
Inside a matrix related entry I am trying to show what they like from that dropdown field value inside a block for 'cricket' and block for 'football'
{% set relatedPeople = craft.entries.section('people').relatedTo(block).all() %}

This gets the channel but I am struggling to then filter by the dropdown value, I thought I could use relatedTo but that's not for dropdown values.
I tried this on the group I created for the dropdown
relatedPeople.peopleGroup('cricket')) 

I get:

Impossible to invoke a method ("peopleGroup") on an array.

Any help would be grateful

**Tags:** craft3

---

## 1 answers

### Answer by username_1 on 2021-09-11. Score: 2 | Accepted answer

Relations won't work here because they only apply to elements (Entries, Categories, Assets, etc). Instead, you can use the field handle to filter by field values depending on the field's type. See, for instance, the documentation of Dropdown Fields to find out how to filter them. In this case, your approach is correct in principle, you can pass a string that matches the value of one of the dropdown options to search for entries with that option selected.
So this should work:
{% set relatedPeople = craft.entries()
    .section('people')
    .peopleGroup('cricket')
    .all()
%}


I get - Impossible to invoke a method ("peopleGroup") on an array.

This is just a minor error, the problem is that you're trying to add a condition after you've already executed the query using .all(). The .all() method returns an array of results, so trying to call a method on that array will result in an error.
If you can't add all conditions in a single expression as I did above - for example, because some conditions are only added in specific situations - make sure only to execute .all() after all conditions have been added. Something like this:
{# Create a query (craft\elements\db\EntryQuery). #}
{% set relatedPeopleQuery = craft.entries().section('people') %}

{# Add more conditions to the query. #}
{% do relatedPeopleQuery.peopleGroup('cricket') %}

{# Execute the query and fetch the results. #}
{% set relatedPeople = relatedPeopleQuery.all() %}

> **Comments:**
> **username_0**: Thanks for the detailed answer, it works great. I have an understanding of how Craft CMS works in regards to the issue. It makes sense now.  
> **username_1**: @smudge18 Glad I could help! Would you mind marking my answer as accepted then? Thanks!  
> **username_0**: All done.. thanks for your help!  

---

