<p>After looking for some more options I found the solution.</p>

<p>At first I was looking for a solution on how to check if the handle was inside of the array but, didn't manage to output the entire array as a conditional. I ended up changing the filter to filter on the category id (should have done that in the first place). </p>

<p>Now I'm filtering by ID so I could just use:</p>

<p><code>{% for entry in entries if selectedCat in entry.categories.ids() %}</code></p>

<p>I got some help from this answer after I figured out to use ID's instead of handle's</p>

<p><a href="https://craftcms.stackexchange.com/questions/17155/converting-array-of-entries-to-an-array-of-ids">Converting array of entries to an array of ids</a></p>

CC BY-SA 3.0
2017-09-15T09:02:21.627Z
2017-09-15T09:02:21.627Z
Justin Dekkers
<p>I have an activity calendar (more like a weekly schedule) which filters per day and per category. Because there are so many activities I can't just load them all in at once so I use some sort of Ajax pagination kind of way which grabs the category handle.</p>

<p>The problem is, it will always use the first category that has been selected for the event instead of going through them all. </p>

<p>So everything works fine as long as 1 category is selected.</p>

<p>Here is my code:</p>

<pre><code>{% if craft.request.getParam('cat') == '' %}
     {% set selectedCat = 'startingCategory' %}
{% else %}
     {% set selectedCat = craft.request.getParam('cat') %}
{% endif %}
&lt;div class="row activiteitenRow" id="tegelContent"&gt;
     {% for category in craft.categories.group('leeftijdsGroepen') %}
          {% set query = {
                 section : 'sportidEvenementen',
                 order : 'evenementDatum desc',
                 limit : null,
                 relatedTo : category,
           } %}
           {% set entries = craft.entries(query) %}
           {% for entry in entries 
                  if entry.categories[0]|camel == selectedCat
            %}

            {# activity display code here #}

            {% endfor %}
      {% endfor %}
&lt;/div&gt;
</code></pre>

<p>I think the problem is in the final forloop:</p>

<p><code>{% for entry in entries if entry.categories[0]|camel == selectedCat %}</code></p>

<p>I used <code>.first()</code> Before but it was obvious that would only grab the first category but it needs to use an array but, really can't find a way to fix this.</p>

<entries><categories><filter><forloop><array>
Load entries based on category field value while multiple categories are selected
# Load entries based on category field value while multiple categories are selected

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

I have an activity calendar (more like a weekly schedule) which filters per day and per category. Because there are so many activities I can't just load them all in at once so I use some sort of Ajax pagination kind of way which grabs the category handle.
The problem is, it will always use the first category that has been selected for the event instead of going through them all. 
So everything works fine as long as 1 category is selected.
Here is my code:
{% if craft.request.getParam('cat') == '' %}
     {% set selectedCat = 'startingCategory' %}
{% else %}
     {% set selectedCat = craft.request.getParam('cat') %}
{% endif %}

     {% for category in craft.categories.group('leeftijdsGroepen') %}
          {% set query = {
                 section : 'sportidEvenementen',
                 order : 'evenementDatum desc',
                 limit : null,
                 relatedTo : category,
           } %}
           {% set entries = craft.entries(query) %}
           {% for entry in entries 
                  if entry.categories[0]|camel == selectedCat
            %}

            {# activity display code here #}

            {% endfor %}
      {% endfor %}


I think the problem is in the final forloop:
{% for entry in entries if entry.categories[0]|camel == selectedCat %}
I used .first() Before but it was obvious that would only grab the first category but it needs to use an array but, really can't find a way to fix this.

**Tags:** entries, categories, filter, forloop, array

---

## 1 answers

### Answer by username_0 on 2017-09-15. Score: 1 | Accepted answer

After looking for some more options I found the solution.

At first I was looking for a solution on how to check if the handle was inside of the array but, didn't manage to output the entire array as a conditional. I ended up changing the filter to filter on the category id (should have done that in the first place).

Now I'm filtering by ID so I could just use:

`{% for entry in entries if selectedCat in entry.categories.ids() %}`

I got some help from this answer after I figured out to use ID's instead of handle's

[Converting array of entries to an array of ids](https://craftcms.stackexchange.com/questions/17155/converting-array-of-entries-to-an-array-of-ids)


---

