# Building a collection of items from several structure fields?

**URL:** <https://forum.getkirby.com/t/building-a-collection-of-items-from-several-structure-fields/16852>\
**Category:** Questions\
**Tags:** v3\
**Created:** [January 13, 2020, 10:59pm UTC](https://forum.getkirby.com/t/building-a-collection-of-items-from-several-structure-fields/16852 "2020-01-13T22:59:01Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![plagasul](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/plagasul/32/4199_2.png) [@plagasul](https://forum.getkirby.com/u/plagasul)\
**Post date:** [January 13, 2020, 10:59pm UTC](https://forum.getkirby.com/t/building-a-collection-of-items-from-several-structure-fields/16852/1 "2020-01-13T22:59:01Z")

</div>

How do I build a collection of items pertaining to several different structure fields?

For example, the following structure fields:

```
$restaurantes = $page->restaurantes()->toStructure();
$hoteles = $page->hoteles()->toStructure();
$transporte = $page->transporte()->toStructure();
$atracciones = $page->atracciones()->toStructure();

$allTogetherNow = ...

```

Specifically I’d like to be able to loop the resulting added structure object or collection without having to recursively enter each structure object within it.

In other words, I want a collection of items, not a collection of structure fields.

Is it possible ?

Thank you

---

<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:** [January 13, 2020, 11:03pm UTC](https://forum.getkirby.com/t/building-a-collection-of-items-from-several-structure-fields/16852/2 "2020-01-13T23:03:08Z")

</div>

Do these structure fields have the same structure? You could merge them just like you merge a page collection etc. but that would probably only make sense if they all have the same fields.

---

<div class="post-metadata">

**Author:** ![plagasul](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/plagasul/32/4199_2.png) [@plagasul](https://forum.getkirby.com/u/plagasul)\
**Post date:** [January 13, 2020, 11:27pm UTC](https://forum.getkirby.com/t/building-a-collection-of-items-from-several-structure-fields/16852/3 "2020-01-13T23:27:41Z")

</div>

Yes they do, how would I merg them ? using add() ?

---

<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:** [January 13, 2020, 11:32pm UTC](https://forum.getkirby.com/t/building-a-collection-of-items-from-several-structure-fields/16852/4 "2020-01-13T23:32:51Z")

</div>

`Add()`, yes.

> **[$structure-\>add()](https://getkirby.com/docs/reference/@/classes/cms/structure/add)**
>
> Adds a single object or an entire second collection to the current collection

---

<div class="post-metadata">

**Author:** ![plagasul](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/plagasul/32/4199_2.png) [@plagasul](https://forum.getkirby.com/u/plagasul)\
**Post date:** [January 13, 2020, 11:35pm UTC](https://forum.getkirby.com/t/building-a-collection-of-items-from-several-structure-fields/16852/5 "2020-01-13T23:35:29Z")

</div>

so:

```
$restaurantes = $page->restaurantes()->toStructure();
$hoteles = $page->hoteles()->toStructure();
$transporte = $page->transporte()->toStructure();
$atracciones = $page->atracciones()->toStructure();

$allTogetherNow = $restaurantes->merge($hoteles)->merge($transporte)->merge(atracciones)

```

Will that result in all the items of each structure field in a single structure object ?

Thank you

---

<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:** [January 13, 2020, 11:37pm UTC](https://forum.getkirby.com/t/building-a-collection-of-items-from-several-structure-fields/16852/6 "2020-01-13T23:37:29Z")

</div>

I edited my post above, `merge` only exists for pages, it seems.

But if you replace `merge()` with `add()` in your example above, that should actually work.

The result will be a single structure you can then loop through.
