I have a section called "Events" and an Entries field, we'll call myEntriesField
to select related entries from another channel called "Exhibitors"
On the Events page, I need to display the related Exhibitors grouped by their categories. And if there are no related Exhibitors in said Event, I need to hide the surrounding html that displays the category title etc.
I have this in my template:
{% set theListings = entry.myEntriesField %}
{% set thisCategory =
theListings.relatedTo(craft.categories.slug('the-category-i-need'))
%}
{% if thisCategory | length %}
<div class="section listings">
<h2>Category Title</h2>
<div class="the-listings">
{% for theEntry in thisCategory %}
<div class="item">
<h3>{{ theEntry.title }}</h3>
...more entry data stuff...
</div>
</div>
{% endfor %}
</div>
</div>
{% endif %}
{% set thisOtherCategory =
theListings.relatedTo(craft.categories.slug('the-next-category-i-need'))
%}
{% if thisOtherCategory | length %}
<div class="section listings">
<h2>Category Title</h2>
<div class="the-listings">
{% for otherEntry in thisOtherCategory %}
<div class="item">
<h3>{{ otherEntry.title }}</h3>
...more entry data stuff...
</div>
</div>
{% endfor %}
</div>
</div>
{% endif %}
But this displaying ALL Exhibitors, grouped by their categories, rather than just the related Exhibitors selected in the Event entry.
Any ideas what I am missing here?