<p>This is not a full fletched solution, but might kickstart you.</p>
<p>One solution would be to add a &quot;vintage&quot; or &quot;brewYear&quot; date field to your entry's section. In twig, you can then use the contents of this field to do you further selections.</p>
<p>Another solution would be to use a second category group containing the years you need. Then, adding another category field (for the years) to the beer section would allow you to relate the entry to this category and subsequently in Twig you are able to filter based on this relation.</p>
<p>If you checkout the <a href="https://craftcms.com/docs/3.x/relations.html#simple-relationships" rel="nofollow noreferrer">documentation for Craft 3 relations</a>, you might see how you can query entry records based on multiple relations.</p>
<p>There is also a demo website on <a href="http://barkeeper.parhelia.ch" rel="nofollow noreferrer">http://barkeeper.parhelia.ch</a> which is based on code published by Pixel &amp; Tonic <a href="https://github.com/craftcms/ontherocks" rel="nofollow noreferrer">here</a>. Its not a 100% fit for what you try to achieve, but has some nice concepts – although it also uses the SuperTable plugin for the drink incredients.</p>

CC BY-SA 4.0
2021-03-08T13:26:31.670Z
2021-03-08T13:26:31.670Z
MisterMike
<p>In this example, I'm trying to show entries with the category &quot;Beer&quot;. This works:</p>
<pre><code>{% set myCategory = craft.categories.slug('beer') %}
 {% if entry.relatedDrinks.relatedTo(myCategory)|length %}
  &lt;h1&gt;Beers&lt;/h1&gt;
  {% for beer in entry.relatedDrinks.relatedTo(myCategory) %}
   {{beer.title }}
  {% endfor %}
{% endif %}
</code></pre>
<p>I also want to limit these entries to a certain year (not defined by Entry Date). I've created a Section called &quot;Product Year&quot; with entries such as &quot;2020&quot; and &quot;2021&quot;. Within the entry for the beer, I've added an Entries field to select the year defined in the Product Year section. I'm not sure how to use that Product Year relation as a filter.</p>
<p>I'm essentially trying to say <code>{% if entry.relatedDrinks.relatedTo(myCategory)|length &quot;and product year is 2020 &quot;%}</code></p>

<craft3>
How do I display entries depending on multiple relations?
# How do I display entries depending on multiple relations?

(Asked by: username_0 on 2021-03-07)

In this example, I'm trying to show entries with the category "Beer". This works:
{% set myCategory = craft.categories.slug('beer') %}
 {% if entry.relatedDrinks.relatedTo(myCategory)|length %}
  Beers
  {% for beer in entry.relatedDrinks.relatedTo(myCategory) %}
   {{beer.title }}
  {% endfor %}
{% endif %}

I also want to limit these entries to a certain year (not defined by Entry Date). I've created a Section called "Product Year" with entries such as "2020" and "2021". Within the entry for the beer, I've added an Entries field to select the year defined in the Product Year section. I'm not sure how to use that Product Year relation as a filter.
I'm essentially trying to say {% if entry.relatedDrinks.relatedTo(myCategory)|length "and product year is 2020 "%}

**Tags:** craft3

---

## 1 answers

### Answer by username_1 on 2021-03-08. Score: 1

This is not a full fletched solution, but might kickstart you.

One solution would be to add a "vintage" or "brewYear" date field to your entry's section. In twig, you can then use the contents of this field to do you further selections.

Another solution would be to use a second category group containing the years you need. Then, adding another category field (for the years) to the beer section would allow you to relate the entry to this category and subsequently in Twig you are able to filter based on this relation.

If you checkout the [documentation for Craft 3 relations](https://craftcms.com/docs/3.x/relations.html#simple-relationships), you might see how you can query entry records based on multiple relations.

There is also a demo website on <http://barkeeper.parhelia.ch> which is based on code published by Pixel & Tonic [here](https://github.com/craftcms/ontherocks). Its not a 100% fit for what you try to achieve, but has some nice concepts – although it also uses the SuperTable plugin for the drink incredients.


---

