Tailor categories filtering

Hi. I use Tailor blueprint called “Events” with categories. I want to filter posts of this type. If I try code like this - {% if events.category == ‘sample’ %}, it does not work. The reason:
{{ events.category }} shows massive in massive

[{"id":1,"site_id":null,"site_root_id":1,"slug":"sample" .... }]

how to show, for example, category slug and to use it for “if” logic

You need to add a whereRelation statement to the query.

{% for event in events.whereRelation('categories', 'sample') %}
    {# code for entry goes here #}
{% endfor %}
1 Like

thank you Artistro, works this code:

{% set event = events.whereRelation('categories', 'slug', 'sample').get() %}
{% for event in event %}
...

or

{% for event in events.whereRelation('status', 'slug', 'sample').get() %}

But if I want to show labels within query, accordingly to category. For example, label “sports”, I have to use “if” logic

1 Like

for example, I show posts of category “sample”, and I want to show labels for taxonomy “attributs”

1 Like

Is it right to use “for” instead “if”:

{% for event_cat in events.whereRelation('categories', 'slug', 'sport').get() %}
<div class="sport_label"><a href="/sport">Sport</a></div>
{% endfor %}
1 Like

If would be better since you can directly reference the tag there, unless it’s multiple tags. Could you explain a bit more on what you’re trying to do?

1 Like

Bit lost here too, how does the tag relate to the event? If it is like the category, then you can chain the queries:

{% for event_cat in events
    .whereRelation('categories', 'slug', 'sport')
    .whereRelation('tags', 'slug', 'foobar')
    .get() %}