<p>If you have infoPage with category A and B lets say.</p>

<p>Then, you have a <strong>Product 1</strong> with category A and B also.</p>

<p>If in your template you do (with <code>entry</code> being the current infoPage entry):</p>

<pre><code>{% set relatedProducts = craft.entries.section('products').relatedTo(entry.relatedCat).all() %}

{% for relatedProduct in relatedProducts %}
    {{ relatedProduct.title }} &lt;br&gt;
{% endfor %}
</code></pre>

<p>You should not get <strong>Product 1</strong> returned to you twice..? Have you actually tried?</p>

CC BY-SA 4.0
2019-01-22T16:29:27.587Z
2019-01-22T16:36:33.623Z
2019-01-22T16:36:33.623Z
Oli
<p>I have a channel (handle: "infopages") with entries.
I have a channel (handle: "products") with entries.
I have a category (handle: "productTypes")</p>

<p>Every entry from "infopages" has a category field, called "relatedCat". Every entry from "products" has a category field, called "relatedCat".</p>

<p>In the template for the infopages, I want to show all entries from "products" that share the same category. So if an infopage is related to the category "robotmowers", I want to show all the entries from "products" that are also related to "robotmowers". Every entry in every channel can be related to multiple categories, that's where the hard part comes in.</p>

<p>I could loop through the "relatedCat" field and get all the related entries from "products" in a loop. However, if multiple categories are selected, that means I possible get the same product entry more than once. I guess there must be a better way to do this?</p>

<relations><relatedto>
Get entries related to same category
# Get entries related to same category

(Asked by: username_0 on 2019-01-21)

I have a channel (handle: "infopages") with entries.
I have a channel (handle: "products") with entries.
I have a category (handle: "productTypes")

Every entry from "infopages" has a category field, called "relatedCat". Every entry from "products" has a category field, called "relatedCat".

In the template for the infopages, I want to show all entries from "products" that share the same category. So if an infopage is related to the category "robotmowers", I want to show all the entries from "products" that are also related to "robotmowers". Every entry in every channel can be related to multiple categories, that's where the hard part comes in.

I could loop through the "relatedCat" field and get all the related entries from "products" in a loop. However, if multiple categories are selected, that means I possible get the same product entry more than once. I guess there must be a better way to do this?

**Tags:** relations, relatedto

---

## 1 answers

### Answer by username_1 on 2019-01-22. Score: 2

If you have infoPage with category A and B lets say.
Then, you have a Product 1 with category A and B also.
If in your template you do (with entry being the current infoPage entry):
{% set relatedProducts = craft.entries.section('products').relatedTo(entry.relatedCat).all() %}

{% for relatedProduct in relatedProducts %}
    {{ relatedProduct.title }} 
{% endfor %}

You should not get Product 1 returned to you twice..? Have you actually tried?


---

