2

I want to find all entries that match the title field where excludeFromSearch != 1 (is false).

{% set query = 'and excludeFromSearch not 1 and ' ~ 'title:"' ~ "myValue" ~ '"' %}

    {% set results = craft.entries({
    section: querySections,
    search: query,
    orderBy: 'score',
    }).limit(50) %}

It does not work. My field excludeFromSearch is a lightswitch.

3

The light switch value should be taken out of the search query and put into the entry query:

{% set query = 'title:"' ~ "myValue" ~ '"' %}
{% set results = craft.entries({
    section: querySections,
    search: query,
    excludeFromSearch: 'not 1',
    orderBy: 'score',
    }).limit(50) %}

Or slightly cleaner / Craft 3:

{% set query = 'title:"' ~ "myValue" ~ '"' %}
{% set entryQuery = craft.entries
    .section(querySections)
    .search(query)
    .excludeFromSearch('not 1')
    .orderBy('score')
    .limit(50)
%}

{% set entries = entryQuery.all() %}
  • 1
    Weird. It wasn't entirely clear from the documentation that you can do this. Thanks! – 4midori Nov 11 '19 at 18:18

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.