Support Log in

Calculation Fields — Automatic Totals (PRO)

User Guide
Prefer video? Watch the Field Forge tutorials 8 short guides covering every feature Watch

A Calculation field is a read-only number field that computes a total automatically. Editors cannot type into it — Field Forge calculates the value from other fields on the same post and displays the result whenever the post is viewed or edited. The total is also stored in the database so your developer can query or expose it through REST or GraphQL without extra computation.

Calculation fields require a PRO license. On the free plan, the field type appears in the picker with a PRO badge.

Two Ways to Calculate a Total

When you add a Calculation field to a field group, you choose a Total source in the field settings:

Formula (self) — write a simple math expression that references other top-level fields in the same field group by wrapping their names in braces. For example:
  • {price} * {qty} multiplies a Price field by a Quantity field
  • ({base_price} + {surcharge}) * {tax_rate} uses parentheses for grouping
  • {subtotal} - {discount} subtracts a discount from a subtotal

Allowed characters: + - * / ( ), digits, and decimal points. Any other characters make the result 0. Field Forge evaluates the formula using a secure mathematical parser — no PHP code is executed.

Sum repeater sub-field — add up a numeric sub-field across every row of a sibling repeater. This is the “line-item totals” pattern: each row in a repeater (for example, an order_items repeater with an item_total sub-field) contributes one number, and the Calculation field returns their sum. You select the repeater name and sub-field name in the field settings — no formula to write.

Output Formatting

A Calculation field can display its result as a plain number, a currency amount, or a percentage. Configure these in the field settings:

SettingOptionsExample
Output formatNumber, Currency, PercentageCurrency → $1,299.00
Decimal places0–102 → 1299.00
Currency symbolAny text$, , £
Symbol positionPrefix or SuffixPrefix → $99, Suffix → 99€
Thousands separatorAny character,1,299
Decimal separatorAny character.1299.00

Live Preview in the Editor

When you or a content manager edit a post and change a value in a sibling field, the Calculation field total updates per-keystroke in the metabox. This is a display preview only — Field Forge recalculates the authoritative total on the server when the post is saved.

Example: Invoice Line Items

Imagine a “Quote” custom post type where a manager fills in line items and needs a grand total automatically:

  1. Add a Repeater field named line_items with sub-fields: description (Text), qty (Number), unit_price (Number), row_total (Number)
  2. Have editors compute each row total manually in the row_total sub-field (or use a formula Calculation sub-field once nested calc support is added)
  3. Add a Calculation field named grand_total
Total source: Sum repeater sub-field

Repeater: line_items, Sub-field: row_total

Output format: Currency, Symbol: $, Decimal places: 2

  1. Editors fill in line items; the grand total displays automatically and cannot be overridden

For a simpler formula-based example with just a price and quantity at the top level:

  • price (Number field) and qty (Number field) are siblings of grand_total (Calculation)
  • Total source: Formula (self), Formula: {price} * {qty}
  • The metabox shows the running total as the editor types

Totalling Values Across Posts

Calculation fields work on one post at a time. To add up a field’s values across many posts — for example, summing all donation amounts across every Campaign post — use the shortcode. This is a free feature.

text
0

Place this shortcode in any post, page, or widget. It reads all published posts of the given type and returns the aggregated result. The op parameter supports sum, avg, min, max, and count.

> Good to know: The shortcode reads directly from Field Forge’s optimized database table, so it is efficient even on sites with thousands of posts. Sub-field values inside repeaters are automatically excluded from the count to prevent double-counting.

Forge AI Assistant Online

Hi! I'm the Field Forge AI assistant. Ask me anything about the plugin — setup, features, troubleshooting, or development.

Just now
Powered by Forge AI · Browse docs