2

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

1 Answer 1

2

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.

1
  • 1
    Work like a charm, thanks
    – Thomas
    Commented Jan 13, 2023 at 15:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.