<p>If you want to search for entries, you can use the <a href="https://craftcms.com/docs/templating/craft.entries#search" rel="nofollow noreferrer">search</a> parameter:</p>

<pre><code>{% set people = craft.entries
    .section('people')
    .search('*xyz* OR *zzzz*') 
%}
</code></pre>

<p>Then, you can loop through those people like this:</p>

<pre><code>{% for person in people |batch(3) %}
    {{ person.name }}
{% endfor %}
</code></pre>

<p>By default, <a href="https://craftcms.com/docs/searching" rel="nofollow noreferrer">search</a> doesn't do fuzzy search, that's where the *s come in. You can, however, <a href="https://craftcms.com/support/enabling-fuzzy-search-by-default" rel="nofollow noreferrer">enable fuzzy search by default</a>.</p>

<p>If you want to limit your search to a field, do:</p>

<pre><code>{% craft.entries.search('fieldHandle:xyz OR fieldHandle:zzzz') %}
</code></pre>

CC BY-SA 3.0
2017-09-18T07:14:26.680Z
I understand that .search can be used to include those search parameters, but how would you exclude those search parameters? So you would get all entries that do NOT include xyz, zzzz. Thanks –
devwest
CC BY-SA 3.0
2017-09-18T07:19:12.800Z
I'm sorry, misread your question. As mentioned on the search page of the Craft docs, I think you can exclude search using the `-`. So I guess that would be `.search('-xyz AND -zzzz')` with fuzzy search enabled, then? Not tested, though.
Paul
CC BY-SA 3.0
2017-09-19T08:39:43.850Z
Hi Paul, i managed to find a way to do it by implementing the following way craft.entries.section('people').title('and, not *xyz*, not *zzzz*).
devwest
CC BY-SA 3.0
2017-09-15T10:56:38.843Z
2017-09-15T10:56:38.843Z
Paul
<p>I'm quite new to Craft CMS and have takeen over an application (using Twig templates).  I'm trying to run a filter but not having much joy so maybe I might get some help!</p>

<p>So, there is a people section (<code>craft.entries.section('people')</code>) with over 1000 entries. These are displayed in an HTML table, each row has 3 columns (handled using the <code>batch()</code> call). I want to exclude certain entries that match a particular condition.</p>

<p>For example, I want to exclude all 'people' that partially match a list of names (e.g 'xyz', 'zzzz', 'joebloggs')</p>

<pre><code>{% for people in craft.entries.section('people').order('title asc').limit(500)|batch(3) %}
</code></pre>

<p>Is it possible to do a query like this before the loop? Or is it something I need to check on each iteration inside the loop? Doing this might make the <code>batch()</code> unusable?</p>

<filter><forloop>
Filtering out section entries
# Filtering out section entries

(Asked by: username_0 on 2017-09-15)

I'm quite new to Craft CMS and have takeen over an application (using Twig templates).  I'm trying to run a filter but not having much joy so maybe I might get some help!
So, there is a people section (craft.entries.section('people')) with over 1000 entries. These are displayed in an HTML table, each row has 3 columns (handled using the batch() call). I want to exclude certain entries that match a particular condition.
For example, I want to exclude all 'people' that partially match a list of names (e.g 'xyz', 'zzzz', 'joebloggs')
{% for people in craft.entries.section('people').order('title asc').limit(500)|batch(3) %}

Is it possible to do a query like this before the loop? Or is it something I need to check on each iteration inside the loop? Doing this might make the batch() unusable?

**Tags:** filter, forloop

---

## 1 answers

### Answer by username_1 on 2017-09-15. Score: 2

If you want to search for entries, you can use the search parameter:
{% set people = craft.entries
    .section('people')
    .search('*xyz* OR *zzzz*') 
%}

Then, you can loop through those people like this:
{% for person in people |batch(3) %}
    {{ person.name }}
{% endfor %}

By default, search doesn't do fuzzy search, that's where the *s come in. You can, however, enable fuzzy search by default.
If you want to limit your search to a field, do:
{% craft.entries.search('fieldHandle:xyz OR fieldHandle:zzzz') %}

> **Comments:**
> **username_0**: I understand that .search can be used to include those search parameters, but how would you exclude those search parameters? So you would get all entries that do NOT include xyz, zzzz. Thanks –  
> **username_1**: I'm sorry, misread your question. As mentioned on the search page of the Craft docs, I think you can exclude search using the `-`. So I guess that would be `.search('-xyz AND -zzzz')` with fuzzy search enabled, then? Not tested, though.  
> **username_0**: Hi Paul, i managed to find a way to do it by implementing the following way craft.entries.section('people').title('and, not *xyz*, not *zzzz*).  

---

