<p>To get the pagination to work as expected, you need to incorporate the if into your <code>craft.entries</code> query. There may be a more elegant solution to do this, but looking at the database, the selected choices is saved as an array-like string:</p>

<pre><code>["blue","red"]
</code></pre>

<p>This means that you can search for the value in the field like this:</p>

<pre><code>craft.entries.section('eventRentals').rentalColor('*"red"*').relatedTo(category).limit(12).order('title')
</code></pre>

CC BY-SA 3.0
2016-02-27T11:29:15.137Z
2016-02-27T11:29:15.137Z
André Elvan
<p>I'm trying to pull all the entries in a category that have a multi-selection selected and then paginate it. </p>

<p>If I just do the below, it works perfectly fine. </p>

<pre><code>{% set entriesRed = craft.entries.section('eventRentals').relatedTo(category) %}
{% for entry in entriesRed if entry.rentalColor.contains('red') %}
            {{ entry.title }}
{% endfor %}
</code></pre>

<p>But now I want to paginate it and I can't quite get the right syntax. To be clear, it's the top part I can't get a hold of, I'm modifying an already working existing pagination so I'm not including the bottom half.</p>

<pre><code>{% paginate craft.entries.section('eventRentals').relatedTo(category).limit(12).order('title') as entries if entry.rentalColor.contains('red') %}
{% for entry in entries %}
    {{ entry.title }}
{% endfor %}
{# blah blah blah rest of the pagination ul li stuff #}
</code></pre>

<p>doesn't work, neither does</p>

<pre><code>{% paginate craft.entries.section('eventRentals').relatedTo(category).limit(12).order('title') as entries %}
{% for entry in entries if entry.rentalColor.contains('red') %}
     {{ entry.title }}
{% endfor %}
</code></pre>

<p>Any tips?</p>

<pagination><forloop><loop>
Combing an If Statement with Pagination
# Combing an If Statement with Pagination

(Asked by: username_0 on 2016-02-26)

I'm trying to pull all the entries in a category that have a multi-selection selected and then paginate it. 
If I just do the below, it works perfectly fine. 
{% set entriesRed = craft.entries.section('eventRentals').relatedTo(category) %}
{% for entry in entriesRed if entry.rentalColor.contains('red') %}
            {{ entry.title }}
{% endfor %}

But now I want to paginate it and I can't quite get the right syntax. To be clear, it's the top part I can't get a hold of, I'm modifying an already working existing pagination so I'm not including the bottom half.
{% paginate craft.entries.section('eventRentals').relatedTo(category).limit(12).order('title') as entries if entry.rentalColor.contains('red') %}
{% for entry in entries %}
    {{ entry.title }}
{% endfor %}
{# blah blah blah rest of the pagination ul li stuff #}

doesn't work, neither does
{% paginate craft.entries.section('eventRentals').relatedTo(category).limit(12).order('title') as entries %}
{% for entry in entries if entry.rentalColor.contains('red') %}
     {{ entry.title }}
{% endfor %}

Any tips?

**Tags:** pagination, forloop, loop

---

## 1 answers

### Answer by username_1 on 2016-02-27. Score: 3 | Accepted answer

To get the pagination to work as expected, you need to incorporate the if into your craft.entries query. There may be a more elegant solution to do this, but looking at the database, the selected choices is saved as an array-like string:
["blue","red"]

This means that you can search for the value in the field like this:
craft.entries.section('eventRentals').rentalColor('*"red"*').relatedTo(category).limit(12).order('title')


---

