<p>Instead of adding the lightswitch field to the <code>search</code> query, add a separate condition as <a href="https://craftcms.com/docs/4.x/lightswitch-fields.html#querying-elements-with-lightswitch-fields" rel="nofollow noreferrer">recommended in the documentation</a>.</p>
<pre class="lang-php prettyprint-override"><code>Entry::find()
    -&gt;search('my search query')
    -&gt;hideFromSearch(true)
    -&gt;all();
</code></pre>
<p>Use <code>true</code> and <code>false</code> to only find entries where the lightswitch is turned on or off, respectively. Then you can deselect <code>Use this field’s values as search keywords</code>, as this condition won't require the search index.</p>

CC BY-SA 4.0
2023-01-13T15:18:16.897Z
Work like a charm, thanks
Thomas
CC BY-SA 4.0
2023-01-13T14:00:14.633Z
2023-01-13T14:00:14.633Z
MoritzLost
<p>I want to exclude some entires from search, so I add a field <code>hideFromSearch</code> and enable <code>Use this field’s values as search keywords</code></p>
<p>It works when I search like</p>
<pre><code>Entry::find()-&gt;search('hideFromSearch::1')-&gt;all();
</code></pre>
<p>But it doesn't work when I search like</p>
<pre><code>Entry::find()-&gt;search('hideFromSearch::0')-&gt;all();
</code></pre>
<p>Always return empty array.
I also tried</p>
<pre><code>Entry::find()-&gt;search('hideFromSearch::&quot;&quot;')-&gt;all();
</code></pre>
<p>No luck.</p>
<p>Craft version: Craft Pro 3.7.55.2</p>

<search><lightswitch>
Search lightswitch field with disabled value
# Search lightswitch field with disabled value

(Asked by: username_0 on 2023-01-13)

I want to exclude some entires from search, so I add a field hideFromSearch and enable Use this field’s values as search keywords
It works when I search like
Entry::find()->search('hideFromSearch::1')->all();

But it doesn't work when I search like
Entry::find()->search('hideFromSearch::0')->all();

Always return empty array.
I also tried
Entry::find()->search('hideFromSearch::""')->all();

No luck.
Craft version: Craft Pro 3.7.55.2

**Tags:** search, lightswitch


---

## 1 answers

### Answer by username_1 on 2023-01-13. Score: 2 | Accepted answer

Instead of adding the lightswitch field to the search query, add a separate condition as recommended in the documentation.
Entry::find()
    ->search('my search query')
    ->hideFromSearch(true)
    ->all();

Use true and false to only find entries where the lightswitch is turned on or off, respectively. Then you can deselect Use this field’s values as search keywords, as this condition won't require the search index.

> **Comments:**
> **username_0**: Work like a charm, thanks  

---

