15

I'm trying to build a search function that excludes results from certain sections all together. This is the code I was trying to use.

{% set entries = craft.entries.search(query).section('not testimonials, not authors').id('not 2').order('score') %} 

When I use just one section, it works fine:

{% set entries = craft.entries.search(query).section('not authors').id('not 2').order('score') %} 

Any thoughts on how I could construct this query?

1 Answer 1

29

The trick is to add and once before the first not

{% set entries = craft.entries.search(query).section('and, not this, not that') %} 
1
  • in Craft 4.x you would write it the following way: .section(['not', 'this','that','someOther']) Commented Jul 4, 2023 at 17:00

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.