Skip to main content

Operators

Operators perform specific operations on values in Expression Language. They enable:

  • Calculations
  • Comparisons
  • Logical decisions
  • String manipulation
  • Data access

This reference covers every available operator with syntax examples and common usage patterns.

Arithmetic Operators

Mathematical operations for calculations and numeric transformations.

OperatorNameSyntaxExampleResultUsage
+Additiona + b5 + 38Add numbers, calculate totals
-Subtractiona - b10 - 46Subtract values, find differences
*Multiplicationa * b6 * 742Multiply numbers, calculate percentages
/Divisiona / b15 / 35Divide numbers, find averages
%Modulusa % b17 % 52Find remainder, check even/odd
**Exponentiationa ** b2 ** 38Calculate powers, exponential growth

Practical examples:

# Calculate total price including tax rate
[[price + (price * tax_rate)]]

# Apply percentage discount to original price
[[original_price - (original_price * discount_percentage / 100)]]

# Alternate CSS classes for table rows
[[index % 2 == 0 ? 'even-row' : 'odd-row']]

# Calculate compound interest over time
[[principal * (1 + rate) ** years]]

Comparison Operators

Compare values and return boolean results for conditional logic.

OperatorNameSyntaxExampleResultUsage
==Equala == b5 == '5'trueLoose equality, type conversion
===Identicala === b5 === '5'falseStrict equality, no type conversion
!=Not Equala != b5 != 3trueLoose inequality
!==Not Identicala !== b5 !== '5'trueStrict inequality
<Less Thana < b3 < 5trueNumeric and alphabetical comparison
>Greater Thana > b10 > 5trueNumeric and alphabetical comparison
<=Less Than or Equala <= b5 <= 5trueInclusive comparison
>=Greater Than or Equala >= b10 >= 8trueInclusive comparison

Practical examples:

# Display different text based on post status
[[post_status == 'publish' ? 'Live' : 'Draft']]

# Check if price falls within acceptable range
[[price >= min_price and price <= max_price]]

# Set user category based on age threshold
[[user_age >= 18 ? 'Adult' : 'Minor']]

# Show availability based on inventory count
[[inventory > 0 ? 'In Stock' : 'Out of Stock']]

Logical Operators

Combine and manipulate boolean values for complex conditional logic.

OperatorNameSyntaxExampleResultUsage
and / &&Logical ANDa and btrue and falsefalseBoth conditions must be true
or / ||Logical ORa or btrue or falsetrueAt least one condition must be true
not / !Logical NOTnot anot truefalseNegates/reverses boolean value

Truth tables and examples:

# Require all conditions to be met
[[is_logged_in and has_permission and is_active]]

# Allow access if user has any qualifying role
[[is_admin or is_editor or is_moderator]]

# Check for opposite condition
[[not is_guest_user]]

# Complex permission checking with grouped conditions
[[is_logged_in and (is_admin or is_editor) and not is_suspended]]

String Operators

Manipulate and combine text values.

OperatorNameSyntaxExampleResultUsage
~Concatenationa ~ b'Hello' ~ ' World''Hello World'Join strings together

Practical examples:

# Combine first and last name with space
[[first_name ~ ' ' ~ last_name]]

# Build dynamic URL from base and page number
[[base_url ~ '/page/' ~ page_number]]

# Format price display with currency symbol
[['Price: $' ~ price ~ ' (' ~ currency ~ ')']]

# Add draft indicator to unpublished posts
[[post_title ~ (post_status != 'publish' ? ' [DRAFT]' : '')]]
About Concatenation Operator

Even if you concatenate non-strings, the output will be a string. For example 1 ~ 2 evaluates to "12" not 12. This means you also cannot concatenate dynamic data, for eg. wp. ~ .post ~ .title will render as wp.post.title not Hello World!

Array Operators

Test array membership and create ranges.

OperatorNameSyntaxExampleResultUsage
inContainsvalue in array'red' in ['red', 'blue']trueCheck if value exists in array
not inDoes Not Containvalue not in array'green' not in ['red', 'blue']trueCheck if value missing from array
..Rangestart..end1..5[1,2,3,4,5]Generate numeric sequences

Practical examples:

# Check if post has any acceptable status
[[post_status in ['publish', 'future', 'private']]]

# Exclude posts from banned or inactive users
[[user_role not in ['banned', 'suspended', 'inactive']]]

# Validate current page within total page count
[[current_page in 1..total_pages]]

# Grant access based on user role membership
[[user_role in ['admin', 'editor'] ? 'Edit Access' : 'Read Only']]

Access Operators

Navigate object properties and array elements.

OperatorNameSyntaxExampleResultUsage
.Property Accessobject.propertyuser.display_nameProperty valueAccess object properties
[]Array Accessarray[index]posts[0]Array elementAccess array elements by index

Practical examples:

# Access nested user information from post
[[wp.post.post_author.display_name]]

# Get name from first category in array
[[categories[0].name]]

# Access featured image URL property
[[featured_image.file_url]]

# Get title from first post in query results
[[wp.posts_query.posts[0].post_title]]

Conditional Operators

Make decisions and provide fallback values.

OperatorNameSyntaxExampleResultUsage
? :Ternarycondition ? true_val : false_valage >= 18 ? 'Adult' : 'Minor'Conditional resultIf/then/else logic
??Null Coalescingvalue ?? fallbackcustom_title ?? post_titleFirst non-null valueProvide fallback values

Practical examples:

# Show personalized greeting based on login status
[[is_logged_in ? 'Welcome back!' : 'Please log in']]

# Handle multiple post states with nested conditions
[[post_status == 'publish' ? 'Published' : (post_status == 'draft' ? 'Draft' : 'Other')]]

# Use first available content source
[[custom_excerpt ?? post_excerpt ?? limit_words(post_content, 30)]]

# Display price or unavailable message with formatting
[[(inventory > 0 and price > 0) ? ('$' ~ price ~ ' - Available') : 'Out of Stock']]

Specialized Operators

Advanced operators for specific use cases.

OperatorNameSyntaxExampleResultUsage
matchesRegex Matchstring matches patternemail matches '/^.+@.+$/'true/falsePattern matching validation
&Bitwise ANDa & b5 & 31Binary operations (advanced)
|Bitwise ORa | b5 | 37Binary operations (advanced)
->Arrow Function(param) -> expression(item) -> item.activeFunctionCallback functions for arrays

Practical examples:

# Validate email format using regex pattern
[[email matches '/^[^@]+@[^@]+\.[^@]+$/' ? 'Valid' : 'Invalid']]

# Detect gallery shortcode in post content
[[post_content matches '/\\[gallery.*?\\]/' ? 'Has Gallery' : 'No Gallery']]

# Filter array to published posts only
[[filter(posts, (post) -> post.post_status == 'publish')]]

# Check permission flags using bitwise operation
[[user_permissions & admin_flag]]

Operator Precedence

Operations are evaluated in specific order. Higher precedence = evaluated first.

PrecedenceOperatorsDescription
500+ - (unary)Positive/negative signs
200**Exponentiation
60* / %Multiplication, division, modulus
40~String concatenation
30+ -Addition, subtraction
25..Range
20< > <= >= == === != !== in not in matchesComparisons
15and &&Logical AND
10or ||Logical OR
5->Arrow functions
0? :Ternary conditional

Precedence examples:

# Multiplication happens before addition
[[2 + 3 * 4]] # Result: 14 (not 20)

# Override precedence with parentheses
[[(2 + 3) * 4]] # Result: 20

# Logical operations follow precedence rules
[[price > 100 and quantity > 0 or is_sale]]
# Evaluates as: (price > 100 and quantity > 0) or is_sale

# Use parentheses for clarity in complex expressions
[[(price > 100 and quantity > 0) or is_sale]]

Common Patterns

Range Checking

[[price >= 50 and price <= 100]]
[[user_age >= 13 and user_age <= 17]]

Status Badges

[[post_status == 'publish' ? 'Live' : 'Draft']]
[[inventory > 0 ? 'Available' : 'Sold Out']]

Safe Operations

# Prevent division by zero
[[total > 0 ? amount / total : 0]]

# Safe string operations
[[title ?? 'Untitled']]

Multiple Conditions

[[is_logged_in and has_permission and not is_banned]]
[[is_sale or (price < 20) or (is_member and price < 50)]]

Common Mistakes

MistakeWrongCorrectWhy
Assignment vs Comparisonstatus = 'active'status == 'active'Use == for comparison
String Addition'Hello' + 'World''Hello' ~ 'World'Use ~ for string concatenation
Precedence5 + 3 * 2(5 + 3) * 2Use parentheses for clarity
Incomplete Ternarycondition ? 'yes'condition ? 'yes' : 'no'Ternary needs both values
Type Confusion'5' === 5'5' == 5Use == for loose comparison
Expression Language Functions

For data transformation capabilities, see: Built-in Functions → - 100+ functions for processing and transforming data

Expression Syntax

For complete syntax rules and structure, see: Expression Syntax → - Language structure, data access, and formatting rules

Operators are the building blocks of Expression Language logic. Master these patterns to create sophisticated conditional logic, calculations, and data transformations throughout your Builderius templates.