Get all entries with linked entry in entries field 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' =&gt; [
  'section' =&gt; 'projects',
  'test' =&gt; 'testValue'
],
Have you read the docs about relations? 

'criteria' =&gt; [
    'section' =&gt; 'projects', 
    'test' =&gt; 'testValue' 
    'relatedTo' =&gt; id
]


Just replace id with the ID of your element 

If you want to filter a specific field you have to include it as an array 

'relatedTo' =&gt; [
    'sourceElement' =&gt; id,
    'field' =&gt; 'fieldHandle'
]