Skip to main content

i4w_math

Usage

This shortcode is designed to allow you to query a contact field in your Keap application, perform a simple math operation on it, display/use it and optionally store the result in Keap.

[ELSE_math] conditional branching is NOT supported.

Shortcode nesting is NOT supported.

Parameters

ParameterDescriptionDefaultRequired
fieldThe name of the field used to perform the operation.noneYes
targetThe name of the field in which to store the results of the operation. If not specified, it defaults to the name provided in "field". If set to the special value 'noupdate' no result will be stored.field valueNo
operationSpecifies the math operation to be performed. Valid operations are: add, sub (subtract), div (divide), mul (multiply), pow (power), mod (modulus), sqr (square root), max (maximum), min (minimum).noneYes
valueThe second operand in the operation to be performed.noneYes (except for sqrt)
roundThe number of decimal digits to round the result of the operation to. If a positive value is provided the rounding will occur after the decimal point, if a negative value is provided the rounding will occur before the decimal point. Halves are always rounded up. 0 means any value will be rounded to an integer.noneNo
flipSpecifies whether the order of the operands should be switched.0 (no)No
showSpecifies if the result of the operation should be returned to WordPress for display or further use within another shortcode.1 (yes)No
formatProvides a sprintf-type format string to apply to the result of the operation. Example: %d formats as an integer, %.2f formats as a floating number with 2 decimal places.noneNo

Example

Add 300 to a field and store the result:

Shortcode
[i4w_math field='_wholenumber' operation='add' value='300' show='1']

Add 300 without storing the result in Keap:

Shortcode
[i4w_math field='_wholenumber' operation='add' value='300' show='1' target='noupdate']

Divide by 2 and round to 2 decimal places:

Shortcode
[i4w_math field='_decimalnumber' operation='divide' value='2' show='0' round='2' format='%.2f']

Notes

info

The format of how the value is stored within Keap depends upon the contact field type. Decimal Number, Text and Currency fields will have the data stored by Keap exactly as calculated by this shortcode. However data stored in a Whole Number field type will be rounded up or down automatically by Keap upon storing the data.