<p>I think what you are trying to achieve here has little to do with the actual templating itself. You can add your tags as data-attributes like so</p>

<pre><code>{% set entries = craft.entries.section('yoursection') %}
&lt;ul&gt;
{% for entry in entries %)
   &lt;li data-tag={% for tags in entry.tagsFieldHandle %){{tag.title}}{% endfor %}&gt;{{entry.title}}&lt;/li&gt;
{% endfor %}
&lt;/ul&gt;
</code></pre>

<p>You set the tags for each entry, so you'll be able to hide/show entries with the right tags.</p>

<p>Then you can simply use javascript on the checkboxes to match for one of these tags in the data attributes.</p>

CC BY-SA 3.0
2017-01-17T22:06:29.827Z
2017-01-17T22:06:29.827Z
Jan_dh
<p>You can combine multiple relationship criteria by passing an array to the <code>relatedTo</code> parameter with the keyword <code>'and'</code> or <code>'or'</code> as the first array element. You want your entries to be related to any of the tags, so this should work for you:</p>

<pre><code>{% set query = craft.request.getQuery() %}

{# Make sure selectedTagIds is an array #}
{% set selectedTagIds = query.tags ?? [] %}

&lt;form action=""&gt;
    {% for tag in craft.tags.group('colorTag') %}
        {% set checkedAttr = tag.id in selectedTagIds ? 'checked' : '' %}
        &lt;input type="checkbox" name="tags[]" value="{{ tag.id }}" {{ checkedAttr }}&gt;{{ tag.name }}&lt;/input&gt;
    {% endfor %}

    {% for tag in craft.tags.group('shapeTag') %}
        {% set checkedAttr = tag.id in selectedTagIds ? 'checked' : '' %}
        &lt;input type="checkbox" name="tags[]" value="{{ tag.id }}" {{ checkedAttr }}&gt;{{ tag.name }}&lt;/input&gt;
    {% endfor %}

    &lt;button type="submit"&gt;Search&lt;/button&gt;
&lt;/form&gt;

{# Prepare our relatedTo parameter #}
{% set relatedToParam = ['or'] %}

{% for id in selectedTagIds %}
    {% set relatedToParam = relatedToParam|merge([{
        targetElement: id
    }]) %}
{% endfor %}

{# Make sure to not pass the param with just the 'or' in the array #}
{% set relatedToParam = relatedToParam|length &gt; 1 ? relatedToParam : null %}

{% set entries = craft.entries({
    section: 'foo',
    relatedTo: relatedToParam,
}) %}

{# Query for the entries and return them #}
{% for entry in entries %}
{% endfor %}
</code></pre>

CC BY-SA 3.0
2017-01-17T19:41:05.323Z
Can you explain where to include the tags name and how to construct the form?. Thanks!
Ricardo Henriquez
CC BY-SA 3.0
2017-01-17T22:48:05.053Z
I’d rather go with the tags’s IDs instead of the names, saves us some work to query for the tags by their names. Updated the answer and added the form to make it complete.
carlcs
CC BY-SA 3.0
2017-01-13T09:45:33.873Z
2017-01-17T22:44:31.963Z
2017-01-17T22:44:31.963Z
carlcs
<p>I am working on a site that requires a filter option based on tags.
Each entry will have two sets of tags (e.g., colors and shapes)</p>

<pre><code>{% for tag in craft.tags.group('colorTag') %}
{% for tag in craft.tags.group('shapeTag') %}
</code></pre>

<p>How can I create a filter that allows you to check boxes for those tags and display the results that match ANY of the selected tags?</p>

<p><a href="https://i.sstatic.net/sbaag.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/sbaag.png" alt="enter image description here"></a></p>

<p>The results will show entries with the Blue tag, entries with the Yellow tag and entries with the Triangle tag. </p>

<p>Thanks so much!</p>

CC BY-SA 3.0
2017-01-10T00:41:33.603Z
You're specifically looking for entries where _any_ of those tags match, correct?  i.e. "blue or yellow or triangle".  Or is it "(blue or yellow) AND triangle"?
Brad Bell
CC BY-SA 3.0
2017-01-10T14:43:01.900Z
Yes, where ANY of the tags match, so any entry with a blue, or a yellow or a triangle tag.
Ricardo Henriquez
CC BY-SA 3.0
2017-01-17T20:17:47.570Z
The filtering is from within the CMS right? Not user-based from the page
Jan_dh
CC BY-SA 3.0
2017-01-17T20:24:36.317Z
@Jan_dh User based from the front-end.
Ricardo Henriquez
<entry><search><filter><tag>
How to filter entries based on Tags
# How to filter entries based on Tags

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

I am working on a site that requires a filter option based on tags.
Each entry will have two sets of tags (e.g., colors and shapes)
{% for tag in craft.tags.group('colorTag') %}
{% for tag in craft.tags.group('shapeTag') %}

How can I create a filter that allows you to check boxes for those tags and display the results that match ANY of the selected tags?

The results will show entries with the Blue tag, entries with the Yellow tag and entries with the Triangle tag. 
Thanks so much!

**Tags:** entry, search, filter, tag

> **Comments:**
> **username_1**: You're specifically looking for entries where _any_ of those tags match, correct?  i.e. "blue or yellow or triangle".  Or is it "(blue or yellow) AND triangle"?  
> **username_0**: Yes, where ANY of the tags match, so any entry with a blue, or a yellow or a triangle tag.  
> **username_2**: The filtering is from within the CMS right? Not user-based from the page  
> **username_0**: @username_2 User based from the front-end.  

---

## 2 answers

### Answer by username_3 on 2017-01-13. Score: 5 | Accepted answer

You can combine multiple relationship criteria by passing an array to the relatedTo parameter with the keyword 'and' or 'or' as the first array element. You want your entries to be related to any of the tags, so this should work for you:
{% set query = craft.request.getQuery() %}

{# Make sure selectedTagIds is an array #}
{% set selectedTagIds = query.tags ?? [] %}


    {% for tag in craft.tags.group('colorTag') %}
        {% set checkedAttr = tag.id in selectedTagIds ? 'checked' : '' %}
        {{ tag.name }}
    {% endfor %}

    {% for tag in craft.tags.group('shapeTag') %}
        {% set checkedAttr = tag.id in selectedTagIds ? 'checked' : '' %}
        {{ tag.name }}
    {% endfor %}

    Search


{# Prepare our relatedTo parameter #}
{% set relatedToParam = ['or'] %}

{% for id in selectedTagIds %}
    {% set relatedToParam = relatedToParam|merge([{
        targetElement: id
    }]) %}
{% endfor %}

{# Make sure to not pass the param with just the 'or' in the array #}
{% set relatedToParam = relatedToParam|length > 1 ? relatedToParam : null %}

{% set entries = craft.entries({
    section: 'foo',
    relatedTo: relatedToParam,
}) %}

{# Query for the entries and return them #}
{% for entry in entries %}
{% endfor %}

> **Comments:**
> **username_0**: Can you explain where to include the tags name and how to construct the form?. Thanks!  
> **username_3**: I’d rather go with the tags’s IDs instead of the names, saves us some work to query for the tags by their names. Updated the answer and added the form to make it complete.  

---

### Answer by username_2 on 2017-01-17. Score: 2

I think what you are trying to achieve here has little to do with the actual templating itself. You can add your tags as data-attributes like so
{% set entries = craft.entries.section('yoursection') %}

{% for entry in entries %)
   {{entry.title}}
{% endfor %}


You set the tags for each entry, so you'll be able to hide/show entries with the right tags.
Then you can simply use javascript on the checkboxes to match for one of these tags in the data attributes.


---

