Element API - Filter on a value from a multi value field I am looking for some assistance with the Element API plugin. I need to filter on the bannerPageCategories field which is a multi select checkbox field. The value will be passed via a querystring value. I can filter on a field with a single value but how do I do this for fields which has an array of values.

Any suggestions will be greatly appreciated.

Sample code and json response is below. 

Json Response:

    {
      title:"Test Banner 4",
      url:"http://localhost:8888/banners/test-banner-4",
      jsonUrl:"http://localhost:8888/api/banners/17",
      content:"Test.", 
       page-categories:[
       {
         label:"ADSL",
         value:"adsl",
         selected:true
       },
       {
        label:"Fibre",
        value:"fibre",
        selected:true
       }
    ],
   campaignId:"sHKJJK",
   targetUrl:"http://xyx.xaws.co.za",
   image1:"//xyx.xaws.co.za/dev/images/banners/banner-lg.png",
   image2:"//xyx.xaws.co.za/dev/images/banners/banner-md.png",
   image3:"//xyx.xaws.co.za/dev/images/banners/banner-sm.png",
   date_published:"2018-05-22T14:06:05+02:00",
   date_modified:"2018-05-22T14:06:05+02:00"
  }


Code:

    'api/banners' =&gt; function () {
        \Craft::$app-&gt;response-&gt;headers-&gt;set('Access-Control-Allow-Origin', '*');
        $target = \Craft::$app-&gt;request-&gt;getQueryParam('target');
        $campaign = \Craft::$app-&gt;request-&gt;getQueryParam('campaign');
        return [
            'elementType' =&gt; Entry::class,
            'criteria' =&gt; [
                'section' =&gt; 'banners',
                'bannerPageCategories' =&gt; $target,
                'campaignId' =&gt; $campaign              
            ],
            'transformer' =&gt; function (Entry $entry) {
                $image1 = $entry-&gt;image1-&gt;first();
                $image2 = $entry-&gt;image2-&gt;first();
                $image3 = $entry-&gt;image3-&gt;first();

                return [
                    'title' =&gt; $entry-&gt;title,
                    'url' =&gt; $entry-&gt;url,
                    'jsonUrl' =&gt; UrlHelper::url("api/banners/{$entry-&gt;id}"),
                    'content' =&gt; $entry-&gt;htmlcontent,
                    'page-categories' =&gt; $entry-&gt;bannerPageCategories,
                    'campaignId' =&gt; $entry-&gt;campaignId,
                    'targetUrl' =&gt; $entry-&gt;targetUrl,
                    'image1' =&gt; $image1 ? $image1-&gt;url : null,
                    'image2' =&gt; $image2 ? $image2-&gt;url : null,
                    'image3' =&gt; $image3 ? $image3-&gt;url : null,
                    'date_published' =&gt; $entry-&gt;postDate-&gt;format(\DateTime::ATOM),
                    'date_modified' =&gt; $entry-&gt;dateUpdated-&gt;format(\DateTime::ATOM),
                ];
            },
        ];
    },


Many thanks!
When you wrap your term in asterisks, e.g. *news*, the generated SQL for this query parameter uses a LIKE operator for the ANDWHERE condition is uses (see Element Queries).

Make sure that the values for the Select field don’t overlap (sportnews and news both matching *news*).

'bannerPageCategories' =&gt; "*{$target}*"