# Run $file-\>update() multiple times?

**URL:** <https://forum.getkirby.com/t/run-file-update-multiple-times/14347>\
**Category:** Questions\
**Tags:** v3\
**Created:** [May 23, 2019, 5:33pm UTC](https://forum.getkirby.com/t/run-file-update-multiple-times/14347 "2019-05-23T17:33:19Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![max](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/max/32/129_2.png) [@max](https://forum.getkirby.com/u/max)\
**Post date:** [May 23, 2019, 5:33pm UTC](https://forum.getkirby.com/t/run-file-update-multiple-times/14347/1 "2019-05-23T17:33:19Z")

</div>

I’m having an issue when $file-\>update() is run multiple times, only the last one seems to work.

I’m writing a plugin that pulls in data from an external API and whenever a file is updated. Below is a stripped down version of the plugin that illustrates the issue. When this plugin/hook runs, the only field added is `Field2: value2`.

Thanks in advance!

```
// plugins/myplugin/index.php
<?php

function fileUpdate($file, $field, $value){
  // in the actual plugin, an api call is made here
  // and multiple fields are updated
  try {
    $file->update([$field => $value]);
  } catch(Exception $e) {
    throw $e;
  }
}

Kirby::plugin('violet/fieldtest', [
  'hooks' => [
    'file.update:after' => function ($file) {
      fileUpdate($file, 'field1', 'value1');
      fileUpdate($file, 'field2', 'value2');
    }
  ]
]);

```

---

<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:** [May 23, 2019, 5:35pm UTC](https://forum.getkirby.com/t/run-file-update-multiple-times/14347/2 "2019-05-23T17:35:24Z")

</div>

Where is the point of doing it like that instead of updating all fields at once?

---

<div class="post-metadata">

**Author:** ![max](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/max/32/129_2.png) [@max](https://forum.getkirby.com/u/max)\
**Post date:** [May 23, 2019, 8:24pm UTC](https://forum.getkirby.com/t/run-file-update-multiple-times/14347/3 "2019-05-23T20:24:28Z")

</div>

@texnixe That should work! wasn’t sure if I was missing something here
