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() %}