# Get multiselect category labels from parent

**URL:** <https://forum.getkirby.com/t/get-multiselect-category-labels-from-parent/21015>\
**Category:** Questions\
**Tags:** v3\
**Created:** [February 1, 2021, 4:48pm UTC](https://forum.getkirby.com/t/get-multiselect-category-labels-from-parent/21015 "2021-02-01T16:48:11Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![mikeharrison](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/mikeharrison/32/9620_2.png) [@mikeharrison](https://forum.getkirby.com/u/mikeharrison)\
**Post date:** [February 1, 2021, 4:48pm UTC](https://forum.getkirby.com/t/get-multiselect-category-labels-from-parent/21015/1 "2021-02-01T16:48:11Z")

</div>

Hi,

I have a parent Case Studies page, on the blueprint for which I have a structure for specifying categories:

```
categories:
  label: Categories
  type: structure
  fields:
    category:
      label: Category
      type: text

```

The children of this page are the individual case studies, on which the editor can select one or more categories for the study, using this multiselect:

```
categories:
  label: Categories
  type: multiselect
  required: true
  options: query
  query:
    fetch: page.parent.categories.toStructure
    text: "{{ structureItem.category }}"
    value: "{{ structureItem.category.slug }}"

```

This then forms the basis of a filtering method. I now need to list the individual case studies on the main case study page, and as part of that listing I would like to include the first category selected for that case study. I have tried this:

```
<?php $caseStudies = $page->children()->listed(); ?>
<?php foreach ($caseStudies as $caseStudy): ?>
<?= $caseStudy->categories()->split()[0] ?? ''; ?>
<?php endforeach ?>

```

Which _sort of_ works, in that it outputs the slug (e.g. **turnkey-solutions** ). I need to output the actual category name (e.g. **Turnkey Solutions** ). Is it possible to find this somehow?

Thanks for any help

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [February 1, 2021, 5:36pm UTC](https://forum.getkirby.com/t/get-multiselect-category-labels-from-parent/21015/2 "2021-02-01T17:36:10Z")

</div>

Yes, that’ s possible if not very straightforward.

```php
<?php 
$categories = $page->categories()->toStructure();
$caseStudies = $page->children()->listed(); 
?>
<?php foreach ($caseStudies as $caseStudy): ?>
  <?php
    $category = $categories->filter(function($item) use($caseStudy) {
      return $item->category()->slug() === $caseStudy->categories()->split(',')[0] ?? '';
    })->first();
    echo $category;
  ?>
<?php endforeach ?>

```

---

<div class="post-metadata">

**Author:** ![mikeharrison](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/mikeharrison/32/9620_2.png) [@mikeharrison](https://forum.getkirby.com/u/mikeharrison)\
**Post date:** [February 2, 2021, 10:22am UTC](https://forum.getkirby.com/t/get-multiselect-category-labels-from-parent/21015/3 "2021-02-02T10:22:09Z")

</div>

Thanks for the quick reply! Unfortunately I am not getting anything output with that code - no error, just no output. I have had a look and can’t work out what I might need to change.

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [February 2, 2021, 5:52pm UTC](https://forum.getkirby.com/t/get-multiselect-category-labels-from-parent/21015/4 "2021-02-02T17:52:26Z")

</div>

Could you please show me what you get in your content file for the structure field with the categories?

---

<div class="post-metadata">

**Author:** ![mikeharrison](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/mikeharrison/32/9620_2.png) [@mikeharrison](https://forum.getkirby.com/u/mikeharrison)\
**Post date:** [February 2, 2021, 7:15pm UTC](https://forum.getkirby.com/t/get-multiselect-category-labels-from-parent/21015/5 "2021-02-02T19:15:40Z")

</div>

Sure, it looks like this:

```
Categories:

-
  category: Mezzanine floor
-
  category: 'Pallet racking & inspections'
-
  category: Shelving
-
  category: Dilapidations
-
  category: 'Removals & relocations'
-
  category: Turnkey solutions
-
  category: Partitioning
-
  category: Dynamic solutions
-
  category: 'Design & fit out'
```

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [February 2, 2021, 7:20pm UTC](https://forum.getkirby.com/t/get-multiselect-category-labels-from-parent/21015/6 "2021-02-02T19:20:44Z")

</div>

Ok, and the child pages then have something like

```auto
category: mezzanine-floor, shelving, removals-relocations 

```

?

---

<div class="post-metadata">

**Author:** ![mikeharrison](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/mikeharrison/32/9620_2.png) [@mikeharrison](https://forum.getkirby.com/u/mikeharrison)\
**Post date:** [February 2, 2021, 7:24pm UTC](https://forum.getkirby.com/t/get-multiselect-category-labels-from-parent/21015/7 "2021-02-02T19:24:16Z")

</div>

This is an example from a child page:

```
----

Categories: pallet-racking-inspections, turnkey-solutions, dynamic-solutions

----
```

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [February 2, 2021, 7:32pm UTC](https://forum.getkirby.com/t/get-multiselect-category-labels-from-parent/21015/8 "2021-02-02T19:32:34Z")

</div>

Ok, I’ve found the issues:

```auto
<?php 
$categories = $page->categories()->toStructure();
$caseStudies = $page->children()->listed(); 
?>
<?php foreach ($caseStudies as $caseStudy): ?>
  <?php
    $category = $categories->filter(function($item) use($caseStudy) {
      return $item->category()->slug() ->value() === ( $caseStudy->categories()->split(',')[0] ?? '' );
    })->first();
    if ( $category ) {
      echo $category->category();
    }
  ?>
<?php endforeach ?>

```

---

<div class="post-metadata">

**Author:** ![mikeharrison](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/mikeharrison/32/9620_2.png) [@mikeharrison](https://forum.getkirby.com/u/mikeharrison)\
**Post date:** [February 2, 2021, 7:43pm UTC](https://forum.getkirby.com/t/get-multiselect-category-labels-from-parent/21015/9 "2021-02-02T19:43:01Z")

</div>

That works perfectly. Awesome, thank you @texnixe !
