<p>The <code>search</code> parameter gives you an entire range of search functionality, as explained in the docs at <a href="https://craftcms.com/docs/3.x/searching.html" rel="noreferrer">https://craftcms.com/docs/3.x/searching.html</a></p>
<p>Using a field handle as a parameter essentially specifies what the value of the field must equates to. How this is determined can vary, based on the field type, but in most cases it will be an exact match.</p>
<p>So in the following example, only entries with the exact plaintext field value <code>something</code> will be returned.</p>
<pre><code>craft.entries.somePlaintextField('something')
</code></pre>
<p>If you dump the query's raw SQL then you will see this.</p>
<pre><code>{{ dump(craft.entries.somePlaintextField('something').getRawSql()) }}

Outputs: SELECT ... WHERE ... AND (`content`.`field_somePlaintextField`='something') ...
</code></pre>

CC BY-SA 4.0
2021-01-28T16:29:44.187Z
2021-01-28T16:29:44.187Z
Ben Croker
<p>With element queries, we can search for elements using <code>search</code> method:</p>
<pre><code>craft.entries.search('someField:something')
</code></pre>
<p>or by using field handle as method:</p>
<pre><code>craft.entries.someField('something')
</code></pre>
<p>How these two techniques are different from each other and when whould we use each?</p>

<elementquery>
Element query - using "search" vs using field handle as query method
# Element query - using "search" vs using field handle as query method

(Asked by: username_0 on 2021-01-23)

With element queries, we can search for elements using search method:
craft.entries.search('someField:something')

or by using field handle as method:
craft.entries.someField('something')

How these two techniques are different from each other and when whould we use each?

**Tags:** elementquery


---

## 1 answers

### Answer by username_1 on 2021-01-28. Score: 6 | Accepted answer

The search parameter gives you an entire range of search functionality, as explained in the docs at https://craftcms.com/docs/3.x/searching.html
Using a field handle as a parameter essentially specifies what the value of the field must equates to. How this is determined can vary, based on the field type, but in most cases it will be an exact match.
So in the following example, only entries with the exact plaintext field value something will be returned.
craft.entries.somePlaintextField('something')

If you dump the query's raw SQL then you will see this.
{{ dump(craft.entries.somePlaintextField('something').getRawSql()) }}

Outputs: SELECT ... WHERE ... AND (`content`.`field_somePlaintextField`='something') ...


---

