# Update specific structure field

**URL:** <https://forum.getkirby.com/t/update-specific-structure-field/16456>\
**Category:** Questions\
**Tags:** v3\
**Created:** [November 26, 2019, 12:55pm UTC](https://forum.getkirby.com/t/update-specific-structure-field/16456 "2019-11-26T12:55:24Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Oli1](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/oli1/32/14419_2.png) [@Oli1](https://forum.getkirby.com/u/Oli1)\
**Post date:** [November 26, 2019, 12:55pm UTC](https://forum.getkirby.com/t/update-specific-structure-field/16456/1 "2019-11-26T12:55:25Z")

</div>

I want to update a specific structure entry. I have tried with that function but it only appends the items to the structure field. Is there a way I can update a specific one?

> [@Structure field update](https://forum.getkirby.com/t/structure-field-update/7854/2):
>
> Here’s an example function: /\*\* \* Add a new element to a kirby structure field \* @param string $page \* @param string $field \* @param array $data \*/ function addToStructure($page, $field, $data = array()){ $fieldData = page($page)-\>$field()-\>yaml(); $fieldData[] = $data; $fieldData = yaml::encode($fieldData); try { page($page)-\>update(array($field =\> $fieldData)); return true; } catch(Exception $e) { return $e…

---

<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:** [November 26, 2019, 1:16pm UTC](https://forum.getkirby.com/t/update-specific-structure-field/16456/2 "2019-11-26T13:16:35Z")

</div>

Example using Starterkit social field:

```auto
$structure = $page->social()->yaml();
$item = $structure[0];
$item['platform'] = 'New Value';
$structure[0] = $item;

dump($structure);

```

---

<div class="post-metadata">

**Author:** ![geodude](https://avatars.discourse-cdn.com/v4/letter/g/eb8c5e/32.png) [@geodude](https://forum.getkirby.com/u/geodude)\
**Post date:** [September 2, 2020, 9:56am UTC](https://forum.getkirby.com/t/update-specific-structure-field/16456/3 "2020-09-02T09:56:29Z")

</div>

I’ve adapted your example to try and update a structure field on a site I’m working on.

See my code below:

```auto
try {
         $structure = page('home')->heroContent()->yaml();

          foreach ($structure as $item) {
             $publishDate = new DateTime($item['publishdate']);
             $todaysDate = new DateTime();

               if ($todaysDate >= $publishDate) {
                  $item['publish'] = 'true';
                } else {
                  $item['publish'] = 'false';
                }
             }

                $home = page('home')->update(array('heroContent' => $structure));

                return true;
             } catch (Exception $e) {
                return $e->getMessage();
            }

```

I’ve checked and the if statement if passing as true. However I’m unsure how to apply the “new” structure to the heroContent field.

@texnixe Would you be able to advise on this?
