# toStructure return nothing

**URL:** <https://forum.getkirby.com/t/tostructure-return-nothing/27394>\
**Category:** Questions\
**Tags:** v3\
**Created:** [December 27, 2022, 2:11pm UTC](https://forum.getkirby.com/t/tostructure-return-nothing/27394 "2022-12-27T14:11:01Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![theamnesic](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/theamnesic/32/11855_2.png) [@theamnesic](https://forum.getkirby.com/u/theamnesic)\
**Post date:** [December 27, 2022, 2:11pm UTC](https://forum.getkirby.com/t/tostructure-return-nothing/27394/1 "2022-12-27T14:11:01Z")

</div>

Hi,

In my blog, I have a list of authors in my blog page with a structure field, like this :

```auto
  authors_tab:
    label: Auteurs
    icon: account

    fields:

      authors:

        label: Auteurs
        type: structure

        fields:
          name:
            label: Prénom
            type: text
            counter: false
          surname:
            label: Nom
            type: text
            counter: false
          mail:
            label: Mail
            type: text
            counter: false
          role:
            label: Rôle
            type: text
            counter: false
          description:
            label: Description
            type: text
            counter: false
          photo:
            label: Photo
            type: files

```

When I try to get the structure with:

```auto
<?php $authors = page('blog')->authors()->toStructure(); ?>

```

It return this instead of my structure field:

```auto
pre: Kirby\Cms\Structure Object
(
    [0] => 0
    [1] => 1
    [2] => 2
)

```

The field:

```auto
<?php $authors = page('blog')->authors(); ?>

```

Return this:

```auto
pre: Kirby\Cms\Field Object
(
    [authors] => - 
  name: Jean
  surname: Quette
  mail: email@email.com
  role: Butcher
  description: Lalalala
  photo:
    - file://qaWOtrVnoOot0QI9
- 
  name: Pierre
  surname: Ponce
  mail: email@email.com
  role: Butcher
  description: Lalalala
  photo:
    - file://Gcl5tMfAtDmxoV9S

```

I don’t understand how toStructure works 🤔 …

Thanks!

---

<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:** [December 27, 2022, 2:57pm UTC](https://forum.getkirby.com/t/tostructure-return-nothing/27394/2 "2022-12-27T14:57:31Z")

</div>

See [$field-\>toStructure() | Kirby CMS](https://getkirby.com/docs/reference/templates/field-methods/to-structure#example__template)

---

<div class="post-metadata">

**Author:** ![theamnesic](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/theamnesic/32/11855_2.png) [@theamnesic](https://forum.getkirby.com/u/theamnesic)\
**Post date:** [December 27, 2022, 3:52pm UTC](https://forum.getkirby.com/t/tostructure-return-nothing/27394/3 "2022-12-27T15:52:05Z")

</div>

I precise, my final goal is finding an author selected in a multiselect field in an article, who is returning an ID.

I was looking for a way to select the good author, that’s why I was searching to show the full structure.

Any idea ?

---

<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:** [December 27, 2022, 4:26pm UTC](https://forum.getkirby.com/t/tostructure-return-nothing/27394/4 "2022-12-27T16:26:06Z")

</div>

> [@theamnesic](#):
>
> who is returning an ID.

where does the id come from? Can’t see an id stored in your structure field.

But basically, you would find the authors from the authors field from a value in another field like this:

```auto
$selectedAuthors = page('blog')->authors()->toStructure()->filter(fn($item) => in_array($item->id(), $page->selectfieldName()->split(',')));

```

---

<div class="post-metadata">

**Author:** ![theamnesic](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/theamnesic/32/11855_2.png) [@theamnesic](https://forum.getkirby.com/u/theamnesic)\
**Post date:** [December 27, 2022, 4:38pm UTC](https://forum.getkirby.com/t/tostructure-return-nothing/27394/5 "2022-12-27T16:38:30Z")

</div>

> where does the id come from? Can’t see an id stored in your structure field.

The id(s) come from the multiselect of an article, in article.yml:

```auto
author:
  label: Auteur(s)
  type: multiselect
  options:
    type: query
    query: site.find("blog").authors.toStructure
    text: "{{ item.name }} {{ item.surname }}"

```

Your solution works well, thank you!  
The only thing, this solution don’t keep the order of the items defined in the multiselect.

---

<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:** [December 27, 2022, 5:03pm UTC](https://forum.getkirby.com/t/tostructure-return-nothing/27394/6 "2022-12-27T17:03:46Z")

</div>

Hm, in that case, it might be better to loop through the values in the multiselect and fetch the corresponding item from the structure field one by one.

---

<div class="post-metadata">

**Author:** ![theamnesic](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/theamnesic/32/11855_2.png) [@theamnesic](https://forum.getkirby.com/u/theamnesic)\
**Post date:** [December 27, 2022, 5:34pm UTC](https://forum.getkirby.com/t/tostructure-return-nothing/27394/7 "2022-12-27T17:34:05Z")

</div>

That’s what I tried to do before posting this topic, but no success 😕

I tried to use [$structure-\>find()](https://getkirby.com/docs/reference/objects/cms/structure/find) and [$structure-\>findByKey()](https://getkirby.com/docs/reference/objects/cms/structure/find-by-key) too, but it return nothing.

---

<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:** [December 27, 2022, 5:47pm UTC](https://forum.getkirby.com/t/tostructure-return-nothing/27394/8 "2022-12-27T17:47:59Z")

</div>

Unfortunately, you didn’t post what you tried:

```auto
<?php

foreach ($page->multiSelectFieldName()->split(',') as $item) {

    if ($author = page('blog')->authors()->toStructure()->findby('whatever here', $item) {
        echo $author->name();
    }
}

```

Still irritated by the ID, because structure field items don’t have an id.

---

<div class="post-metadata">

**Author:** ![theamnesic](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/theamnesic/32/11855_2.png) [@theamnesic](https://forum.getkirby.com/u/theamnesic)\
**Post date:** [December 27, 2022, 6:13pm UTC](https://forum.getkirby.com/t/tostructure-return-nothing/27394/9 "2022-12-27T18:13:03Z")

</div>

OK I understand!

Thank you very much Sonja, works like a charm 🙏
