2

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?

1 Answer 1

3

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')
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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