Skip to content

Utility Functions

Utility functions provide general-purpose helpers for data manipulation, encoding, and text processing.

default

Returns the value if it is not null or empty; otherwise returns the fallback.

Signature: default(value, fallback?)

ParameterTypeDefaultDescription
valuemixed--The value to check.
fallbackmixed""The fallback value if value is null or empty.
`{ {default(row.nickname, row.name)}}`
// If nickname is empty, show name

`{ {default(row.bio, 'No bio provided')}}`

`{ {default(row.avatar, '/images/default-avatar.png')}}`

count

Returns the number of elements in an array. Returns 0 for non-array values.

Signature: count(array)

`{ {count(row.items)}}` items
// 5 items

`{ {count(row.tags) > 0 ? join(row.tags, ', ') : 'No tags'}}`

json_encode

Converts a value to a JSON string.

Signature: json_encode(value)

`{ {json_encode(row.settings)}}`
// {"theme":"dark","lang":"en"}

Useful for passing structured data to JavaScript or storing as a string.

json_decode

Parses a JSON string into an array/object.

Signature: json_decode(string)

`{ {count(json_decode(row.tags_json))}}` tags

Returns an empty array if parsing fails.

random

Returns a random integer between min and max (inclusive).

Signature: random(min?, max?)

ParameterTypeDefaultDescription
minnumber0Minimum value (inclusive).
maxnumberPHP_INT_MAXMaximum value (inclusive).
`{ {random(1, 100)}}`
// Random number between 1 and 100

`{ {random(1, 6)}}`
// Simulates a dice roll

slug

Converts a string to a URL-friendly slug using WordPress sanitize_title().

Signature: slug(value)

`{ {slug(row.title)}}`
// "Hello World! 2025" → "hello-world-2025"

`{ {slug(row.name)}}`
// "John O'Brien" → "john-obrien"

truncate

Truncates a string to a maximum length, appending a suffix if truncated.

Signature: truncate(value, length?, suffix?)

ParameterTypeDefaultDescription
valuestring--The string to truncate.
lengthnumber100Maximum character count.
suffixstring"..."String to append when truncated.
`{ {truncate(row.description, 150)}}`
// "A very long description that..." (150 chars + "...")

`{ {truncate(row.title, 50, ' [more]')}}`
// "The quick brown fox jumps [more]"

If the string is shorter than length, it is returned unchanged (no suffix added).

remap

Restructures an object by mapping new field names to old field names.

Signature: remap(source, mappingJson)

ParameterTypeDescription
sourceobject/arrayThe source object to remap.
mappingJsonstringA JSON string mapping {"newKey": "oldKey", ...}.
{ {remap(row, '{"title": "post_title", "body": "post_content"}')}}
// { post_title: "Hello", post_content: "..." } → { title: "Hello", body: "..." }

Returns an empty array if the source is not an array. Returns the source unchanged if the mapping JSON is invalid.

Use in Mapping nodes

The remap() function is most commonly used in the Mapping node to restructure rows from an API or WordPress query:

expression: remap(row, '{"name": "post_title", "date": "post_date", "author": "post_author"}')

Examples

Safe division with default

`{ {default(number_format(row.total / max(row.count, 1), 2), '0.00')}}`

Generate a unique key

`{ {slug(row.title) ~ '-' ~ random(1000, 9999)}}`

Truncated preview with item count

`{ {truncate(row.body, 200)}}` (`{ {count(json_decode(row.attachments))}}` attachments)