<p>Following is an example of using the search feature in a GET request with parameter 'search'.  </p>

<pre><code>return [
    'elementType' =&gt; 'Entry',
    'criteria' =&gt; ['search' =&gt; (craft()-&gt;request-&gt;getParam('search')) ? 'title:'.craft()-&gt;request-&gt;getParam('search') : '' ],
    'paginate' =&gt; true,
    'elementsPerPage' =&gt; 10,
    'pageParam' =&gt; 'pg',
    'transformer' =&gt; new ListTransformer(),
];`
</code></pre>

<p>I assume you can use this instead of the custom transformer class that is being used in the above example:</p>

<pre><code>'transformer' =&gt; function(EntryModel $entry) {
    return [
        'title' =&gt; $entry-&gt;title,
        'url' =&gt; $entry-&gt;url,
        'summary' =&gt; $entry-&gt;summary,
        'body' =&gt; $entry-&gt;body,
    ];
},
</code></pre>

CC BY-SA 3.0
2016-06-01T14:06:15.453Z
How would I use this in the URL? Like this: `search.json?search=title:test` ?
Erik
CC BY-SA 3.0
2016-06-01T14:16:44.820Z
URL format is correct I haven't delved too deeply into search syntax for parameters like title:test
mine is search.json?search=test that is global search
Mark Watson
CC BY-SA 3.0
2016-06-01T14:18:37.523Z
The syntax for search=title:test is correct
Mark Watson
CC BY-SA 3.0
2016-06-01T14:18:39.190Z
Hmm, ok. Doesn't seem to fetch anything. I will tinker with it. Thanks.
Erik
CC BY-SA 3.0
2016-06-01T14:23:52.993Z
Try this
`title:"*test*"`
Mark Watson
CC BY-SA 3.0
2016-06-01T14:30:15.860Z
Negative, I updated with two different approaches I tried.
Erik
CC BY-SA 3.0
2016-06-01T14:31:42.790Z
Let us [continue this discussion in chat](http://chat.stackexchange.com/rooms/40609/discussion-between-green-plastic-and-mark-watson).
Erik
CC BY-SA 3.0
2016-06-01T13:57:59.780Z
2016-06-02T05:21:25.257Z
2016-06-02T05:21:25.257Z
Mark Watson
<p>I can't seem to find this anywhere. Thanks.</p>

<p><strong>Update:</strong></p>

<pre><code>'api/entry/search.json' =&gt; function() {
    return [
        'elementType' =&gt; 'Entry',
        'criteria' =&gt; [
            'search' =&gt; (craft()-&gt;request-&gt;getParam('search')) ? craft()-&gt;request-&gt;getParam('search') : '' 
        ],
        'first' =&gt; true,
        'transformer' =&gt; function(EntryModel $entry) {
            return [
                'title' =&gt; $entry-&gt;title,
                'url' =&gt; $entry-&gt;url,
            ];
        },
    ];
},
</code></pre>

<p>Using the url: <code>api/entry/search.json?search=title:test</code> did not work.</p>

<hr>

<p>This code works, but the title needs to be exact:</p>

<pre><code>'api/entry/search.json' =&gt; function() {
    return [
        'elementType' =&gt; 'Entry',
        'criteria' =&gt; [
            'title' =&gt; craft()-&gt;request-&gt;getParam('title')
        ],
        'first' =&gt; true,
        'transformer' =&gt; function(EntryModel $entry) {
            return [
                'title' =&gt; $entry-&gt;title,
                'url' =&gt; $entry-&gt;url,
            ];
        },
    ];
},
</code></pre>

<p>Using this url: <code>api/entry/search.json?title=Test%20Article</code>, works, but not <code>api/entry/search.json?title=Test</code></p>

<plugin-elementapi>
How do I use the Element API to search via entry title?
# How do I use the Element API to search via entry title?

(Asked by: username_0 on 2016-06-01)

I can't seem to find this anywhere. Thanks.
Update:
'api/entry/search.json' => function() {
    return [
        'elementType' => 'Entry',
        'criteria' => [
            'search' => (craft()->request->getParam('search')) ? craft()->request->getParam('search') : '' 
        ],
        'first' => true,
        'transformer' => function(EntryModel $entry) {
            return [
                'title' => $entry->title,
                'url' => $entry->url,
            ];
        },
    ];
},

Using the url: api/entry/search.json?search=title:test did not work.

This code works, but the title needs to be exact:
'api/entry/search.json' => function() {
    return [
        'elementType' => 'Entry',
        'criteria' => [
            'title' => craft()->request->getParam('title')
        ],
        'first' => true,
        'transformer' => function(EntryModel $entry) {
            return [
                'title' => $entry->title,
                'url' => $entry->url,
            ];
        },
    ];
},

Using this url: api/entry/search.json?title=Test%20Article, works, but not api/entry/search.json?title=Test

**Tags:** plugin-elementapi


---

## 1 answers

### Answer by username_1 on 2016-06-01. Score: 5 | Accepted answer

Following is an example of using the search feature in a GET request with parameter 'search'.  
return [
    'elementType' => 'Entry',
    'criteria' => ['search' => (craft()->request->getParam('search')) ? 'title:'.craft()->request->getParam('search') : '' ],
    'paginate' => true,
    'elementsPerPage' => 10,
    'pageParam' => 'pg',
    'transformer' => new ListTransformer(),
];`

I assume you can use this instead of the custom transformer class that is being used in the above example:
'transformer' => function(EntryModel $entry) {
    return [
        'title' => $entry->title,
        'url' => $entry->url,
        'summary' => $entry->summary,
        'body' => $entry->body,
    ];
},

> **Comments:**
> **username_0**: How would I use this in the URL? Like this: `search.json?search=title:test` ?  
> **username_1**: URL format is correct I haven't delved too deeply into search syntax for parameters like title:test mine is search.json?search=test that is global search  
> **username_1**: The syntax for search=title:test is correct  
> **username_0**: Hmm, ok. Doesn't seem to fetch anything. I will tinker with it. Thanks.  
> **username_1**: Try this `title:"*test*"`  
> **username_0**: Negative, I updated with two different approaches I tried.  
> **username_0**: Let us [continue this discussion in chat](http://chat.stackexchange.com/rooms/40609/discussion-between-green-plastic-and-mark-watson).  

---

