Answers.Body: <p>You can query on multiple category groups like so:</p>
  
  <pre><code>craft.categories.group('suitability, finish, shape, material, edge, surface').all()
  </code></pre>
  
  <p>It can also be done with an array:</p>
  
  <pre><code>craft.categories.group([
    'suitability',
    'finish',
    'shape',
    'material',
    'edge',
    'surface'
  ]).all()
  </code></pre>
  
  <p>Whenever you invoke <code>.all()</code> it returns an array. As those arrays were merged, they created a larger array. In that last bit of code, <code>categories.orderBy()</code> failed because <code>categories</code> was an array and arrays do not have a method named <code>orderBy</code>.</p>
  
  <p>Hope that helps!</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-01-02T21:15:11.637Z
Answers.LastActivityDate: 2019-01-02T21:15:11.637Z
Answers.UserDisplayName: Sam Hernandez
Body: <p>I have got multiple category groups and I need to concatenate them into one list for a filter UI element.</p>
  
  <p>At the moment I have the following:</p>
  
  <pre><code>{% set categories = craft.categories.group('colour').all() %}
  {% set categories = categories|merge(craft.categories.group('suitability').all()) %}
  {% set categories = categories|merge(craft.categories.group('finish').all()) %}
  {% set categories = categories|merge(craft.categories.group('shape').all()) %}
  {% set categories = categories|merge(craft.categories.group('material').all()) %}
  {% set categories = categories|merge(craft.categories.group('edge').all()) %}
  {% set categories = categories|merge(craft.categories.group('surface').all()) %}
  </code></pre>
  
  <p>So now I have a list of all the categories within these groups, I can loop over them as follows:</p>
  
  <pre><code>&lt;ul class="categories"&gt;
      {% for cat in categories %}
          &lt;li class="categories__item"&gt;
              &lt;button class="button categories__btn"&gt;{{ cat.title }}&lt;/button&gt;
          &lt;/li&gt;
      {% endfor %}
  &lt;/ul&gt;
  </code></pre>
  
  <p>But the issue I'm having is that the array of categories is outputting them in the order they're being added. I tried this:</p>
  
  <pre><code>{% set categories = categories.orderBy('title asc').all() %} 
  </code></pre>
  
  <p>But it returns "Impossible to invoke a method ("orderBy") on an array."</p>
  
Tags: <categories><ordering><order><sort>
Title: How to create ordered list of categories from multiple category groups
ThreadText: # How to create ordered list of categories from multiple category groups
  
  (Asked by: username_0 on 2019-01-02)
  
  I have got multiple category groups and I need to concatenate them into one list for a filter UI element.
  
  At the moment I have the following:
  
  ```
  {% set categories = craft.categories.group('colour').all() %}
  {% set categories = categories|merge(craft.categories.group('suitability').all()) %}
  {% set categories = categories|merge(craft.categories.group('finish').all()) %}
  {% set categories = categories|merge(craft.categories.group('shape').all()) %}
  {% set categories = categories|merge(craft.categories.group('material').all()) %}
  {% set categories = categories|merge(craft.categories.group('edge').all()) %}
  {% set categories = categories|merge(craft.categories.group('surface').all()) %}
  
  ```
  
  So now I have a list of all the categories within these groups, I can loop over them as follows:
  
  ```
  <ul class="categories">
      {% for cat in categories %}
          <li class="categories__item">
              <button class="button categories__btn">{{ cat.title }}</button>
          </li>
      {% endfor %}
  </ul>
  
  ```
  
  But the issue I'm having is that the array of categories is outputting them in the order they're being added. I tried this:
  
  ```
  {% set categories = categories.orderBy('title asc').all() %} 
  
  ```
  
  But it returns "Impossible to invoke a method ("orderBy") on an array."
  
  **Tags:** categories, ordering, order, sort
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2019-01-02. Score: 2 | Accepted answer
  
  You can query on multiple category groups like so:
  
  ```
  craft.categories.group('suitability, finish, shape, material, edge, surface').all()
  
  ```
  
  It can also be done with an array:
  
  ```
  craft.categories.group([
    'suitability',
    'finish',
    'shape',
    'material',
    'edge',
    'surface'
  ]).all()
  
  ```
  
  Whenever you invoke `.all()` it returns an array. As those arrays were merged, they created a larger array. In that last bit of code, `categories.orderBy()` failed because `categories` was an array and arrays do not have a method named `orderBy`.
  
  Hope that helps!
  
  
  ---
  
  