3

This is my search results query:

{% set query = craft.request.getParam('q') %}
{% set miniCards = craft.entries.search(query).order('score').limit(12) %}

I have a lightswitch field called showInSearch. When it is set to 1 the entry should not appear in search results.

Problem
When I do this I always get zero results on my searches:

{% set query = craft.request.getParam('q') %}
{% set miniCards = craft.entries.search(query ~' -showInSearch:1').order('score').limit(12) %}

Whereas when I do the opposite I get all results with the search term and the lightswitch field set to 1.

{% set query = craft.request.getParam('q') %}
{% set miniCards = craft.entries.search(query ~' showInSearch:1').order('score').limit(12) %}

I also tried -showInSearch::1,-showInSearch::"1", -showInSearch:"1" and showInSearch:0 to no avail. What am I doing wrong?

Problem persists even after rebuilding search indexes.

4

Instead of adding the filtering criteria to the search parameter, I would use a custom field parameter for the showInSearch field.

{% set miniCards = craft.entries.search(query).showInSearch('not 1').limit(12) %}
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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