Skip to content

Kirby 5.0.2

$page->increment()

Increment a given field value

$page->increment(string $field, int $by = 1, int|null $max = null): Kirby\Cms\Page

Parameters

Name Type Default
$fieldrequired string no default value
$by int 1
$max intornull null

Return type

Kirby\Cms\Page

This method does not modify the existing $page object but returns a new object with the changes applied. Learn more →

Parent class

Kirby\Cms\Page inherited from Kirby\Cms\ModelWithContent

Examples

<?php $page->increment('likes') ?>
The increment method will only work reliably with field values that PHP can parse into a valid integer. Otherwise the field value will be evaluated as zero and incremented to 1 or whatever $by value you pass.