Collect all of the categories used in child entries and list them

I’d like to collect all of the categories attached to all of the this section’s children pages, how do I merge the lists and remove duplicates? (Categories are being added to subpages using multiselect.)
Then I’d like to loop through them with links.

  1. get index of all children
  2. grab which categories are added to them
  3. merge all of these categories
  4. remove duplicates
  5. foreach loop them

The logic seems easy for me, the syntax is not. Thanks in advance!

Kirby has a method for this, called pluck():

$categories = $page->children()->pluck('categories', ',', true);

This will give you an array of all unique categories from all subpages.
Replace categories with name of field if it is different.

2 Likes

Omg. So simple. Thank you so much! Have a great weekend!