Display related entries on a category page filtered by another category field I have a Structure called &quot;Stoves&quot;.
Each Entry has two Category fields 'fuelType' and 'output'.

Fuel Type categories = ''Wood Burning','Multi-Fuel','Gas' and 'Electric'.
Output categories = '4kW','6kW','8kW','10kW',

On the category page template the following simple code gives me the correct entries based on the 'fuelType' field...  e.g. when viewing the 'Wood burning' page it shows me Wood Burning stoves.
{% set entries = craft.entries.relatedTo(category).all() %}

{% for entry in entries %}
    &lt;a href=&quot;{{ entry.url }}&quot;&gt;{{ entry.title }}&lt;/a&gt;&lt;br&gt;
{% endfor %}

But I now need to also loop through the 'output' category group so I get something like the following:
ALL Wood Burning Stoves
Intro Text
start loop

4kW Stoves

Stove_4kW_No.1

Stove_4kW_No.2

Stove_4kW_No.3

6kW Stoves

Stove_6kW_No.1

Stove_6kW_No.2

8kW Stoves

Stove_8kW_No.1

Stove_8kW_No.2

Stove_8kW_No.3

Stove_8kW_No.4


...and so on....
end loop
Is this even possible?  Alternatively could I pull with individual entry queries using the individual 'output' category slugs?
Many thanks
You'd typically use the group filter for this. Depending on what you need to output, be sure to also use eager loading to improve performance.
{% set groupedEntries = craft.entries.with(['yourOutputCatFieldHandle']).relatedTo(category).all()|group('yourOutputCatFieldHandle[0].title') %}

{% for cat, entries in groupedEntries %}
    &lt;h3&gt;{{ cat }}&lt;/h3&gt;
    &lt;ul&gt;
        {% for entry in entries %}
            &lt;li&gt;&lt;a href=&quot;{{ entry.url }}&quot;&gt;{{ entry.title }}&lt;/a&gt;&lt;/li&gt;
        {% endfor %}
    &lt;/ul&gt;
{% endfor %}

EDIT: alternative answer below to allow for using the correct category ordering as per the control panel's Structure order.
Note: this approach requires the supersort plugin.
{# ======================================
First, fetch entries related to this category,
then group the array by each category's
`lft` structure position, then sort the array
by those keys with supersort's ksort function
========================================= #}

{% set groupedEntries = craft.entries.with([
        'yourOutputCatFieldHandle'
    ])
    .relatedTo(category)
    .all()|group('yourOutputCatFieldHandle[0].lft')|supersort('ksort')
%}

{# ======================================
Next, create a hash map of those categories so we can
match up the `lft` left structure position
with the category's title later.
(google &quot;Nested Sets&quot; if you're really bored)
========================================= #}

{% if groupedEntries|length %}
    {% set catTitlesMap = craft.categories.group('yourOutputCatGROUPHandle').all()|group('lft') %}
{% endif %}

{# ======================================
Finally, loop through the grouped array,
matching up the accessory's `lft` position
with the hash map to get the right title...
========================================= #}

{% for cat, entries in groupedEntries %}
    &lt;h3&gt;{{ catTitlesMap[cat][0].title }}&lt;/h3&gt;
    &lt;ul&gt;
        {% for entry in entries %}
            &lt;li&gt;&lt;a href=&quot;{{ entry.url }}&quot;&gt;{{ entry.title }}&lt;/a&gt;&lt;/li&gt;
        {% endfor %}
    &lt;/ul&gt;
{% endfor %}