<p>Your search syntax of <code>craft.entries.section('pages').search('foo:bar foo2:bar2')</code> should work and is the equivalent of saying "give me all of the entries in the <code>pages</code> section where the field <code>foo</code> is equal to <code>bar</code> <strong>and</strong> the field <code>foo2</code> is equal to <code>bar2</code>.</p>

<p>Something that trips people up often is that Craft doesn't do fuzzy searching by default. So <code>foo:bar</code> will match <em>exactly</em> <code>bar</code>, but it will not match <code>bars</code>.  You'd need to use <code>foo:bar*</code> for that.</p>

CC BY-SA 3.0
2015-06-12T05:52:37.137Z
Oh, maybe I'm wrong somewhere else then. My search uses a lightswitch and a position:

craft.entries.section('pages').search('onHomePage::true position::"left"')

I get the pages who are not "onHomePage" as well
Julien
CC BY-SA 3.0
2016-11-23T21:59:17.977Z
And it appears for OR searches this works: search('foo:bar OR foo2:bar2')
JamesNZ
CC BY-SA 4.0
2018-07-04T14:26:00.833Z
Just to clarify, as foo and bar are petpeeves of mine that I find ... less than helpful; the syntax is .search('fieldHandle:textToFind otherFieldHandle:someOtherText')
Matt Wilcox
CC BY-SA 3.0
2015-06-12T05:27:24.477Z
2015-06-12T05:27:24.477Z
Brad Bell
<p>My question could seem obvious but I don't find the solution.</p>

<p>How to make a search on two fields, like:</p>

<pre><code>craft.entries.section('pages').search('foo:bar foo2:bar2')
</code></pre>

<p>I tried</p>

<pre><code>search('foo:bar', 'foo2:bar4')
search('foo:bar and foo2:bar2')
</code></pre>

<p>none of these seem to work</p>

<search>
multiple search
# multiple search

(Asked by: username_0 on 2015-06-12)

My question could seem obvious but I don't find the solution.
How to make a search on two fields, like:
craft.entries.section('pages').search('foo:bar foo2:bar2')

I tried
search('foo:bar', 'foo2:bar4')
search('foo:bar and foo2:bar2')

none of these seem to work

**Tags:** search


---

## 1 answers

### Answer by username_1 on 2015-06-12. Score: 6

Your search syntax of `craft.entries.section('pages').search('foo:bar foo2:bar2')` should work and is the equivalent of saying "give me all of the entries in the `pages` section where the field `foo` is equal to `bar` **and** the field `foo2` is equal to `bar2`.

Something that trips people up often is that Craft doesn't do fuzzy searching by default. So `foo:bar` will match *exactly* `bar`, but it will not match `bars`. You'd need to use `foo:bar*` for that.

> **Comments:**
> **username_0**: Oh, maybe I'm wrong somewhere else then. My search uses a lightswitch and a position:  craft.entries.section('pages').search('onHomePage::true position::"left"')  I get the pages who are not "onHomePage" as well  
> **username_2**: And it appears for OR searches this works: search('foo:bar OR foo2:bar2')  
> **username_3**: Just to clarify, as foo and bar are petpeeves of mine that I find ... less than helpful; the syntax is .search('fieldHandle:textToFind otherFieldHandle:someOtherText')  

---

