How to search on multiple (custom) fields using Element API I am using the Element API to search for entries that match a search query: either the title OR the excerpt should contain the query term. The entry is very simple and has these fields:
-title
-excerpt
-link
when I use this to only search in the title field it works:
$section_handle = ['item'];
$q = Craft::$app-&gt;request-&gt;getParam('query');

$criteria = [
   'section' =&gt; $section_handle, 
   'search' =&gt; 'title:'.$q
];

So I thought I just add the excerpt field like this:
$criteria = [
   'section' =&gt; $section_handle, 
   'search' =&gt; 'title:'.$q.' OR '.'excerpt:'.$q
];

but this did NOT work and I found out that it just won't search that excerpt field, this also does not work:
   $criteria = [
   'section' =&gt; $section_handle, 
   'search' =&gt; 'excerpt:'.$q
];

After some research I found out that when I use this as the 'criteria' it works:
$criteria = [
    'section' =&gt; $section_handle, 
    'excerpt' =&gt; &quot;*{$q}*&quot;
];

And now I wonder how to proceed. How can I either get the first example to work to search in the excerpt field, or add the OR title clause to my latest example where I am able to search in the excerpt field...
I hope this makes sense and that someone can point me in the right direction!
Thanks very much,
Wouter
In your last example:
$criteria = [
    'section' =&gt; $section_handle, 
    'excerpt' =&gt; &quot;*{$q}*&quot;
];

You are making a fuzzy search by surrounding your keyword(s) with * (see docs for syntaxes) and I wonder if that's why you are seeing results (I'd need to see the keywords/entry).
However, if that works, then this should work for you:
'criteria' =&gt; [
    'section' =&gt; $section_handle,
    'search' =&gt; ($q ? 'title:' . $q . ' OR '.'excerpt:*'. $q . '*' : null),
],

Alternatively, make everything fuzzy (not as precise):
'criteria' =&gt; [
    'section' =&gt; $section_handle,
    'search' =&gt; ($q ? 'title:*' . $q . '* OR '.'excerpt:*'. $q . '*' : null),
],

One final thought, if your section has three fields, if you only check Use this field’s values as search keywords on your Settings → Fields → excerpt field then you can search on both title + excerpt simply by doing:
'criteria' =&gt; [
    'section' =&gt; $section_handle,
    'search' =&gt; ($q ?? null),
],