I have a channel called 'projects'.
This channel has two entries fields
:
- relatedThemes
- relatedAreas
What I want to do is perform a search query which filters all projects where the relatedThemes
field has an entry with a certain id
.
I figured out how to search custom fields. Here's an example of a filter with a plain text field with a handle test
.
{% set entries = craft.entries({
section: 'projects'
}).search('test:testValue') %}
This returns all project entries where the test
field has the testValue
value, as expected.
But I can't seem to make this work with an entries field. I thought I could do something like this
{% set entries = craft.entries({
section: 'projects'
}).search('entriesfield.id:relatedThemesID') %}
But this does not work.
Another important thing is that I can't actually use template logic, because the query is to be used in the element api (for Craft 2).
I'm not a backend dev, so I test the criteria
array in templates first and then convert it to php.
So the correct criteria array for the test text field would be
'criteria' => [
'section' => 'projects',
'test' => 'testValue'
],