Using a Matrix field to create a homepage that shows entries from sections and categories I have set up 3 channel types - A, B &amp; C and a Category. Each entry type shares the same pool of categories.
On the home page, I have created a Matrix field (homeSections) with a block type heroSections that has A, B &amp; C in a dropdown (mediaType) and a Category select (homeSection), so I can have &quot;select mediaType A that has Category 1&quot; as an option.
This is what I have so far
{% set entry = craft.entries().section('home').one() %}

{% for block in entry.homeSections.all() %}

    {% switch block.type %}

    {% case &quot;heroSections&quot; %}

        {% for entry in block.homeSection.all() %}

            &lt;h3&gt;{{ entry.title }} {{ block.mediaType.label }}&lt;/h3&gt;
            
            {% set section = block.mediaType %}
            {% set category = entry.slug %}
            {% set entries = craft.entries.section(section).limit(4).orderby('postDate desc').all() %}

            {% include '_includes/listing' %}
        {% endfor %}

{% endswitch %}

{% endfor %}

but I can't figure out how to then filter the results so that the category is applied to the entries returned.
I figured it out.
I changed
{% set category = entry.slug %}
{% set entries = craft.entries.section(section).limit(4).orderby('postDate desc').all() %}

to
{% set category = craft.categories.slug(entry.slug) %}
{% set entries = craft.entries.section(section).relatedTo(category).limit(4).orderby('postDate desc').all() %}

and it shows up as expected.