# $page-\>increment($field) in multilang environment

**URL:** <https://forum.getkirby.com/t/page-increment-field-in-multilang-environment/9658>\
**Category:** Questions\
**Tags:** v2\
**Created:** [February 8, 2018, 1:58pm UTC](https://forum.getkirby.com/t/page-increment-field-in-multilang-environment/9658 "2018-02-08T13:58:45Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![bvdputte](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/bvdputte/32/8179_2.png) [@bvdputte](https://forum.getkirby.com/u/bvdputte)\
**Post date:** [February 8, 2018, 1:58pm UTC](https://forum.getkirby.com/t/page-increment-field-in-multilang-environment/9658/1 "2018-02-08T13:58:45Z")

</div>

How can I use `$page->increment($field)` in a multilingual site so that the value of $field is language agnostic?  
I have tried adding `translate: false` in the blueprint, but that didn’t help.

Thx

---

<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 8, 2018, 2:08pm UTC](https://forum.getkirby.com/t/page-increment-field-in-multilang-environment/9658/2 "2018-02-08T14:08:24Z")

</div>

As far as I can see, there is, unfortunately, no way of passing a language to the `increment()` method. I’d try to use the underlying `$page->update()`method instead.

---

<div class="post-metadata">

**Author:** ![bvdputte](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/bvdputte/32/8179_2.png) [@bvdputte](https://forum.getkirby.com/u/bvdputte)\
**Post date:** [February 8, 2018, 2:23pm UTC](https://forum.getkirby.com/t/page-increment-field-in-multilang-environment/9658/3 "2018-02-08T14:23:15Z")

</div>

Pity.

For future reference; this works -\>

```
try {
    $page->update(array("subscriptionscount" => $page->content("nl")->subscriptionscount()->value() + 1), "nl");
} catch(Exception $e) {
    echo $e->getMessage();
}

```

Thx for clarifying, @texnixe

---

<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 8, 2018, 4:23pm UTC](https://forum.getkirby.com/t/page-increment-field-in-multilang-environment/9658/4 "2018-02-08T16:23:21Z")

</div>

Or as a custom method:

```auto
page::$methods['plusOne'] = function($page, $field, $by = 1, $max = null, $lang = null) {
  $page->update([
    $field => function($value) use($by, $max) {
      $new = (int)$value + $by;
      return ($max and $new >= $max) ? $max : $new;
    }
  ], $lang);
  return $page;
};

```

Use in template:

```auto
$page->plusOne('subscriptionscount', 1, null, 'nl');

```

---

<div class="post-metadata">

**Author:** ![bvdputte](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/bvdputte/32/8179_2.png) [@bvdputte](https://forum.getkirby.com/u/bvdputte)\
**Post date:** [February 8, 2018, 5:47pm UTC](https://forum.getkirby.com/t/page-increment-field-in-multilang-environment/9658/5 "2018-02-08T17:47:07Z")

</div>

@texnixe, Brilliant. This should be the `$page->increment()` behaviour. 😜

---

<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 9, 2018, 11:13am UTC](https://forum.getkirby.com/t/page-increment-field-in-multilang-environment/9658/6 "2018-02-09T11:13:32Z")

</div>

I added it to the [custom method collection](https://github.com/texnixe/kirby-custom-methods/blob/master/page-methods/plus-one.php) and created an issue on GitHub:

> <https://github.com/getkirby/kirby/issues/632>

---

<div class="post-metadata">

**Author:** ![distantnative](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/distantnative/32/11319_2.png) [@distantnative](https://forum.getkirby.com/u/distantnative)\
**Post date:** [February 6, 2025, 5:30pm UTC](https://forum.getkirby.com/t/page-increment-field-in-multilang-environment/9658/7 "2025-02-06T17:30:07Z")

</div>

Archived on February 6, 2025, 5:30pm UTC


