# Duplicated page entries in structure field are not showing

**URL:** <https://forum.getkirby.com/t/duplicated-page-entries-in-structure-field-are-not-showing/30773>\
**Category:** Questions\
**Created:** [February 12, 2024, 6:57pm UTC](https://forum.getkirby.com/t/duplicated-page-entries-in-structure-field-are-not-showing/30773 "2024-02-12T18:57:54Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![anta](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/anta/32/13394_2.png) [@anta](https://forum.getkirby.com/u/anta)\
**Post date:** [February 12, 2024, 6:57pm UTC](https://forum.getkirby.com/t/duplicated-page-entries-in-structure-field-are-not-showing/30773/1 "2024-02-12T18:57:54Z")

</div>

Hello, I have a structure field where the client is able to create an entry and choose a page. Additionally, they can choose how the page is displayed (in a slider, static etc) based on the site settings.

My issue comes when I want to have two or more same pages (duplicated) to be showed in different styles. No matter how many duplicates I have in the structure, only the latest of the duplicated will show.

Is this standard behaviour? Is there a way to tweak this to allow to show all these without needing to duplicate the pages in question?

Thanks in advance.

---

<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 12, 2024, 6:59pm UTC](https://forum.getkirby.com/t/duplicated-page-entries-in-structure-field-are-not-showing/30773/2 "2024-02-12T18:59:47Z")

</div>

> [@anta](#):
>
> No matter how many duplicates I have in the structure, only the latest of the duplicated will show.

It would be helpful if you post your code, thanks!

---

<div class="post-metadata">

**Author:** ![anta](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/anta/32/13394_2.png) [@anta](https://forum.getkirby.com/u/anta)\
**Post date:** [February 12, 2024, 7:24pm UTC](https://forum.getkirby.com/t/duplicated-page-entries-in-structure-field-are-not-showing/30773/3 "2024-02-12T19:24:45Z")

</div>

The code has evolved so much that I think will be confusing to share the full code, but I was curious if that’s standard behaviour or by default it should show all items no matter if they’re duplicates of the same page.

Essentially I am doing:

> $items = $page-\>projects()-\>toStructure();  
> foreach ($items as $item): ?\>  
> $item-\>project()-\>toPage())

Not sure if that’s enough to add some clarity. Happy to try to expand this more without it becoming too confusing.

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:** [February 12, 2024, 7:42pm UTC](https://forum.getkirby.com/t/duplicated-page-entries-in-structure-field-are-not-showing/30773/4 "2024-02-12T19:42:09Z")

</div>

If I understand correctly, in your structure you have a field called `project` which is a pages field. And the structure field can have the same page selected in multiple of these project fields.

But I don’t see why the same page should **not** be displayed multiple times with the code you show above.

---

<div class="post-metadata">

**Author:** ![anta](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/anta/32/13394_2.png) [@anta](https://forum.getkirby.com/u/anta)\
**Post date:** [February 13, 2024, 9:47am UTC](https://forum.getkirby.com/t/duplicated-page-entries-in-structure-field-are-not-showing/30773/5 "2024-02-13T09:47:37Z")

</div>

Yes, that’s correct. I found out this morning my local version of the site displays the duplicated items normally, but the one in production doesn’t. It’s really strange. I will keep digging to see what useful information I can find. Thanks!

---

<div class="post-metadata">

**Author:** ![anta](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/anta/32/13394_2.png) [@anta](https://forum.getkirby.com/u/anta)\
**Post date:** [February 13, 2024, 10:43am UTC](https://forum.getkirby.com/t/duplicated-page-entries-in-structure-field-are-not-showing/30773/6 "2024-02-13T10:43:33Z")

</div>

I figured out where the issue is.

I have this function in config.php that re-indexes the items url’s from the original page to the duplicated one once duplicating a page. That way, when duplicating a page, the links from the newly duplicated structure page are linked to the new page instead of the original one.

I realised the problem happens on these duplicated pages only, not the original ones. Any idea why this could be happen?

```auto
    // Update structure field on duplicate
    'page.duplicate:after' => function ($duplicatePage, $originalPage) {
        $projects = $duplicatePage->projects()->toStructure()->toArray(); // Get the projects structure field

        foreach ($projects as &$project) {

            if (!empty($project['project']) && is_array($project['project'])) {
                $originalProjectName = explode('/', $project['project'][0]);
                $originalProjectNameSlug = end($originalProjectName);
                $duplicatedProjectPage = $duplicatePage->children()->findBy('slug', $originalProjectNameSlug); // Find corresponding page in the duplicated
                $project['project'] = [$duplicatedProjectPage->id()]; // Assign the new project page object
            }

            if (!empty($project['selection']) && is_array($project['selection'])) {
                $originalProjectNames = $project['selection'];
                $duplicatedProjectPages = [];

                foreach ($originalProjectNames as $originalProjectName) {
                    $originalProjectNameSlug = explode('/', $originalProjectName);
                    $originalProjectNameSlug = end($originalProjectNameSlug);
                    $duplicatedProjectPage = $duplicatePage->children()->findBy('slug', $originalProjectNameSlug); // Find corresponding page in the duplicated
                    if ($duplicatedProjectPage) {
                        $duplicatedProjectPages[] = $duplicatedProjectPage->id(); // Add the new project page object to the array
                    }
                }

                $project['selection'] = $duplicatedProjectPages; // Assign the array of new project page objects
            }

        }

        $duplicatePage->update([
            'projects' => Yaml::encode($projects), // Update the projects structure field with YAML-encoded array
        ]);
    },

```

Thanks again!

---

<div class="post-metadata">

**Author:** ![anta](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/anta/32/13394_2.png) [@anta](https://forum.getkirby.com/u/anta)\
**Post date:** [February 24, 2024, 9:15am UTC](https://forum.getkirby.com/t/duplicated-page-entries-in-structure-field-are-not-showing/30773/7 "2024-02-24T09:15:00Z")

</div>

Hi, apologies for bumping this. I’ve been trying to figure out what the issue might be but can’t figure it out. Is someone able to say, based on the code I shared, why once duplicating a page using the config function here, the structure content is duplicated too correctly, but on duplicating an item from the structure, it won’t show. Thanks agian!

---

<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 24, 2024, 9:32am UTC](https://forum.getkirby.com/t/duplicated-page-entries-in-structure-field-are-not-showing/30773/8 "2024-02-24T09:32:32Z")

</div>

What is your Kirby version?

The pages field usually stores UUIDs of the pages, not ids, so the duplication code is a bit confusing, unless you have disabled UUIDs or are using a different type of field.

Please provide the information necessary to understand what is happening here.

Also, it would be interesting to see the content of an original page that works and a duplicated one that doesn’t.

---

<div class="post-metadata">

**Author:** ![anta](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/anta/32/13394_2.png) [@anta](https://forum.getkirby.com/u/anta)\
**Post date:** [February 26, 2024, 4:58pm UTC](https://forum.getkirby.com/t/duplicated-page-entries-in-structure-field-are-not-showing/30773/9 "2024-02-26T16:58:05Z")

</div>

Hi Sonja,  
Kirby version used is 3.5.4. If updating, should I then change id() to uuid()? Or is there something I can do while keeping this current version?

Regarding content, what happens is that if I have i.e 4 duplicated items in the structure, only the last one will display.

---

<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 26, 2024, 5:00pm UTC](https://forum.getkirby.com/t/duplicated-page-entries-in-structure-field-are-not-showing/30773/10 "2024-02-26T17:00:15Z")

</div>

I see, so no uuids yet. But please, show me the content of the duplicated pages (at least the structure related content).

---

<div class="post-metadata">

**Author:** ![anta](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/anta/32/13394_2.png) [@anta](https://forum.getkirby.com/u/anta)\
**Post date:** [February 26, 2024, 5:15pm UTC](https://forum.getkirby.com/t/duplicated-page-entries-in-structure-field-are-not-showing/30773/11 "2024-02-26T17:15:04Z")

</div>

That’s two items from the structure field, the last being a duplicated of the first one.  
I’ve removed non-relevant stuff.

```auto
- 
  how: project
  project:
    - >
      artists/artist/project-1
  header: ""
  selection: []
  style: fullscreen
  id: "12"
- 
  how: project
  project:
    - >
      artists/artist/project-1
  header: ""
  selection: []
  style: standard
  id: "12"

```

Could it be the fact that it has the same ID?

---

<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 26, 2024, 5:36pm UTC](https://forum.getkirby.com/t/duplicated-page-entries-in-structure-field-are-not-showing/30773/12 "2024-02-26T17:36:14Z")

</div>

> [@anta](#):
>
> Could it be the fact that it has the same ID?

No, if you select the same page twice, it should have the same id. And as long as you don’t try to collect them into a collection but loop through them one by one, each project should be rendered fine, unless the pages do not exist. But if one exists and the second one is the same, that should be expected.
