How to create ordered list of categories from multiple category groups 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:

&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;


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."
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!