Answers.Body: <p>Finally figured it out, I had been so close! The following works:</p>
  
  <pre><code>{% set days       = craft.categories.group('day') %}
  {% set activities = craft.categories.group('activity') %}
  
      {% for day in days %}
          &lt;h2&gt;{{ day.title }}&lt;/h2&gt;
  
          {% for activity in activities %}
              {% set entries = craft.entries.section('attractions').relatedTo(
                'and',
                { targetElement: day },
                { targetElement: area }
              ) %}
  
              {% if entries | length %}
                  &lt;h3&gt;{{ area.title }}&lt;/h3&gt;
  
                  {% for entry in entries %}
                      &lt;p&gt;&lt;a href="{{ entry.url }}"&gt;{{ entry.title }}&lt;/a&gt; {{ entry.startTime|date('H:i') }}&lt;/p&gt;
                  {% endfor %}
              {% endif %}
          {% endfor %}
      {% endfor %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-08-06T14:44:54.187Z
Answers.LastActivityDate: 2015-08-06T14:44:54.187Z
Answers.UserDisplayName: Matt Wilcox
Answers.Body: <p>Finally figured it out, I had been so close! The following works:</p>
  
  <pre><code>{% set days       = craft.categories.group('day').slug(abc) %}
  {% set activities = craft.categories.group('activity').slug(xyz) %}
  
  {% for day in days %}
      &lt;h2&gt;{{ day.title }}&lt;/h2&gt;
  
      {% for activity in activities %}
          {% set entries = craft.entries.section('attractions').relatedTo(
            'and',
            { targetElement: day },
            { targetElement: area }
          ) %}
  
          {% if entries | length %}
              &lt;h3&gt;{{ area.title }}&lt;/h3&gt;
  
              {% for entry in entries %}
                  &lt;p&gt;&lt;a href="{{ entry.url }}"&gt;{{ entry.title }}&lt;/a&gt; 
                  {{ entry.startTime|date('H:i') }}&lt;/p&gt;
              {% endfor %}
          {% endif %}
      {% endfor %}
  {% endfor %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-01-06T18:02:54.303Z
Answers.LastActivityDate: 2019-01-07T02:29:58.347Z
Answers.LastEditDate: 2019-01-07T02:29:58.347Z
Answers.UserDisplayName: yogesh yadav
Body: <p>I'm struggling to figure out how to do this:</p>
  
  <ul>
  <li>We have a bunch of entries in single a channel.</li>
  <li>There are two category groups an entry can be assigned to, with multiple categories in each group.</li>
  </ul>
  
  <p>We want to show all entries, but grouped in a nested format as follows:</p>
  
  <ul>
  <li>Loop through Category Group One and get the entries grouped by each category.</li>
  <li>Within each Group One category, loop through Category Group Two, to output entries grouped by Category Group Two categories.</li>
  </ul>
  
  <p>I've found Relations hard enough to wrap my head around when I'm passing just a single category, but this has melted my mind completely.</p>
  
  <p>For more specifics:</p>
  
  <ul>
  <li>Category Group One has categories which are days of the week: Mon, Tue, Wed, Thus, Fri, Sat, Sun.</li>
  <li>Category Group Two has categories that are activities: Walking, Running, Skiing</li>
  </ul>
  
  <p>The output ought to be grouped something like:</p>
  
  <pre><code>Mon - Walking [entry title, entry title, entry title]
  Mon - Running [entry title]
  Mon - Skiing  [entry title, entry title]
  Tue - Walking [...]
  Tue - Running [...]
  ...
  </code></pre>
  
  <p>This is the code I've got closest with, but it's outputting duplicate entries within each day group...</p>
  
  <pre><code>{% set days       = craft.categories.group('day') %}
  {% set activities = craft.categories.group('activity') %}
  
  {% for day in days %}
      &lt;li&gt;
          {{ day.title }}
          {% for activity in activities %}
              {{ activity.title }}
              {% for entry in craft.entries.section('attractions').relatedTo(
                  'and',
                  { targetElement: day },
                  { targetElement: activity }
              ) %}
                      {% if loop.first %}&lt;ul&gt;{% endif %}
                      &lt;li&gt;&lt;a href="{{ entry.url }}"&gt;{{ entry.title }}&lt;/a&gt;&lt;/li&gt;
                      {% if loop.last %}&lt;/ul&gt;{% endif %}
              {% endfor %}
          {% endfor %}
      &lt;/li&gt;
  {% endfor %}
  </code></pre>
  
Tags: <entries><categories>
Title: Sorting Entries by category, from multiple category groups
ThreadText: # Sorting Entries by category, from multiple category groups
  
  (Asked by: username_0 on 2015-08-05)
  
  I'm struggling to figure out how to do this:
  
  * We have a bunch of entries in single a channel.
  * There are two category groups an entry can be assigned to, with multiple categories in each group.
  
  We want to show all entries, but grouped in a nested format as follows:
  
  * Loop through Category Group One and get the entries grouped by each category.
  * Within each Group One category, loop through Category Group Two, to output entries grouped by Category Group Two categories.
  
  I've found Relations hard enough to wrap my head around when I'm passing just a single category, but this has melted my mind completely.
  
  For more specifics:
  
  * Category Group One has categories which are days of the week: Mon, Tue, Wed, Thus, Fri, Sat, Sun.
  * Category Group Two has categories that are activities: Walking, Running, Skiing
  
  The output ought to be grouped something like:
  
  ```
  Mon - Walking [entry title, entry title, entry title]
  Mon - Running [entry title]
  Mon - Skiing  [entry title, entry title]
  Tue - Walking [...]
  Tue - Running [...]
  ...
  
  ```
  
  This is the code I've got closest with, but it's outputting duplicate entries within each day group...
  
  ```
  {% set days       = craft.categories.group('day') %}
  {% set activities = craft.categories.group('activity') %}
  
  {% for day in days %}
      <li>
          {{ day.title }}
          {% for activity in activities %}
              {{ activity.title }}
              {% for entry in craft.entries.section('attractions').relatedTo(
                  'and',
                  { targetElement: day },
                  { targetElement: activity }
              ) %}
                      {% if loop.first %}<ul>{% endif %}
                      <li><a href="{{ entry.url }}">{{ entry.title }}</a></li>
                      {% if loop.last %}</ul>{% endif %}
              {% endfor %}
          {% endfor %}
      </li>
  {% endfor %}
  
  ```
  
  **Tags:** entries, categories
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_0 on 2015-08-06. Score: 3 | Accepted answer
  
  Finally figured it out, I had been so close! The following works:
  
  ```
  {% set days       = craft.categories.group('day') %}
  {% set activities = craft.categories.group('activity') %}
  
      {% for day in days %}
          <h2>{{ day.title }}</h2>
  
          {% for activity in activities %}
              {% set entries = craft.entries.section('attractions').relatedTo(
                'and',
                { targetElement: day },
                { targetElement: area }
              ) %}
  
              {% if entries | length %}
                  <h3>{{ area.title }}</h3>
  
                  {% for entry in entries %}
                      <p><a href="{{ entry.url }}">{{ entry.title }}</a> {{ entry.startTime|date('H:i') }}</p>
                  {% endfor %}
              {% endif %}
          {% endfor %}
      {% endfor %}
  
  ```
  
  
  ---
  
  ### Answer by username_1 on 2019-01-06. Score: 1
  
  Finally figured it out, I had been so close! The following works:
  
  ```
  {% set days       = craft.categories.group('day').slug(abc) %}
  {% set activities = craft.categories.group('activity').slug(xyz) %}
  
  {% for day in days %}
      <h2>{{ day.title }}</h2>
  
      {% for activity in activities %}
          {% set entries = craft.entries.section('attractions').relatedTo(
            'and',
            { targetElement: day },
            { targetElement: area }
          ) %}
  
          {% if entries | length %}
              <h3>{{ area.title }}</h3>
  
              {% for entry in entries %}
                  <p><a href="{{ entry.url }}">{{ entry.title }}</a> 
                  {{ entry.startTime|date('H:i') }}</p>
              {% endfor %}
          {% endif %}
      {% endfor %}
  {% endfor %}
  
  ```
  
  
  ---
  
  