How can I filter selected/related entries by their categories? 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 %}
        &lt;div class="section listings"&gt;
            &lt;h2&gt;Category Title&lt;/h2&gt;
            &lt;div class="the-listings"&gt;
            {% for theEntry in thisCategory %}
                &lt;div class="item"&gt;
                    &lt;h3&gt;{{ theEntry.title }}&lt;/h3&gt;
                    ...more entry data stuff...
                    &lt;/div&gt;
                &lt;/div&gt;
            {% endfor %}
            &lt;/div&gt;
        &lt;/div&gt;
        {% endif %}



        {% set thisOtherCategory = 
             theListings.relatedTo(craft.categories.slug('the-next-category-i-need')) 
        %}

        {% if thisOtherCategory | length %}
        &lt;div class="section listings"&gt;
            &lt;h2&gt;Category Title&lt;/h2&gt;
            &lt;div class="the-listings"&gt;
            {% for otherEntry in thisOtherCategory %}
                &lt;div class="item"&gt;
                    &lt;h3&gt;{{ otherEntry.title }}&lt;/h3&gt;
                    ...more entry data stuff...
                    &lt;/div&gt;
                &lt;/div&gt;
            {% endfor %}
            &lt;/div&gt;
        &lt;/div&gt;
        {% 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?
Start by looping thru each category. Say, all categories in a category group called "eventsCategories." Then find entries related to each category (if any).

{# loop through each of the categories #}
{% for category in craft.categories.group('eventsCategories') %}

  {# find the exhibitor entries that are related to both the Event entry and category #}
  {% set categoryListings = craft.entries({
    section: 'exhibitors',
    relatedTo: ['and',
      { sourceElement: entry, field: 'myEntriesField' },
      { targetElement: category, field: 'myCategoriesField' }
    ]
  }) %}

  {# Only show this category if there were any related exhibitors #}
  {% if categoryListings|length %}

    &lt;h2&gt;{{ category.title }}&lt;/h2&gt;

    {% for listing in categoryListings %}
      &lt;h3&gt;{{ listing.title}}&lt;/h3&gt;
    {% endfor %}

  {% endif %}
{% endfor %}