<p>I got it.</p>

<pre><code>'criteria' =&gt; [ 'title' =&gt; '*'.Craft::$app-&gt;request-&gt;getParam("key").'*' ]
</code></pre>

CC BY-SA 4.0
2018-12-12T12:06:40.290Z
2018-12-12T12:06:40.290Z
Flying Car 0013
<p>I am trying to retrieve search suggestions for a search form. I sent the parameter entered by the user, but how do I do it in the criteria?
I tried this:</p>

<pre><code>'criteria' =&gt; [
    'search' =&gt; 'title: *'.Craft::$app-&gt;request-&gt;getParam("key").'*'
],
</code></pre>

<p>but it does not return any results. What am I doing wrong?
this is my entire endpoint:</p>

<pre><code>'suggests' =&gt;function(){
        return [
            'elementType' =&gt; Product::class,
            'paginate' =&gt; false,
            'pretty' =&gt; true,
            'criteria' =&gt; [
                'limit' =&gt; 15,
                'search' =&gt; 'title: *'.Craft::$app-&gt;request-&gt;getParam("key").'*'
            ],
            'transformer' =&gt; function(Product $product)  {
                return [
                    'title' =&gt; $product-&gt;title,
                    'url' =&gt; $product-&gt;url
                ];
            },
        ];
    },
</code></pre>

CC BY-SA 4.0
2018-12-11T10:45:27.527Z
Got it. LOL 
'criteria' => [
                    'title' => '*'.Craft::$app->request->getParam("key").'*'
                ],
that was fast.
Flying Car 0013
CC BY-SA 4.0
2018-12-12T05:05:21.143Z
Glad you got it sorted! Would you mind adding that as an official answer in case it ends up helping someone in the future?
Brad Bell
<plugin-elementapi><plugin-craftcommerce2>
Check if title field has a string in ElementAPI
# Check if title field has a string in ElementAPI

(Asked by: username_0 on 2018-12-11)

I am trying to retrieve search suggestions for a search form. I sent the parameter entered by the user, but how do I do it in the criteria?
I tried this:
'criteria' => [
    'search' => 'title: *'.Craft::$app->request->getParam("key").'*'
],

but it does not return any results. What am I doing wrong?
this is my entire endpoint:
'suggests' =>function(){
        return [
            'elementType' => Product::class,
            'paginate' => false,
            'pretty' => true,
            'criteria' => [
                'limit' => 15,
                'search' => 'title: *'.Craft::$app->request->getParam("key").'*'
            ],
            'transformer' => function(Product $product)  {
                return [
                    'title' => $product->title,
                    'url' => $product->url
                ];
            },
        ];
    },

**Tags:** plugin-elementapi, plugin-craftcommerce2

> **Comments:**
> **username_0**: Got it. LOL  'criteria' => [                     'title' => '*'.Craft::$app->request->getParam("key").'*'                 ], that was fast.  
> **username_1**: Glad you got it sorted! Would you mind adding that as an official answer in case it ends up helping someone in the future?  

---

## 1 answers

### Answer by username_0 on 2018-12-12. Score: 1

I got it.
'criteria' => [ 'title' => '*'.Craft::$app->request->getParam("key").'*' ]


---

