Skip to content
GravityKit
Buy
Sign in
0 items
  • Plugins

    GravityKit All Access

    Our complete Kit of essential tools for extending and enhancing Gravity Formsโ€”everything you need to build powerful web apps and workflows.

    Learn more
    • GravityView

      GravityView

      Bestseller

      Display Gravity Forms entries on the front-end of your site and build powerful web applications.

    • GravityImport

      GravityImport

      Trending

      Import entries from CSV files into Gravity Forms to transfer data, create new forms, or update existing entries.

    • GravityEdit

      GravityEdit

      Quickly edit Gravity Forms entries inline to save time, reduce clicks, and streamline your workflow.

    • GravityCharts

      GravityCharts

      Trending

      Turn Gravity Forms entries into interactive charts and graphs.

    • GravityActions

      GravityActions

      Update multiple Gravity Forms entries at once, send bulk emails, and streamline your workflow.

    • GravityCalendar

      GravityCalendar

      Turn Gravity Forms entries into dynamic calendars to showcase events, schedules, appointments, and more.

    • GravityExport

      GravityExport

      Export Gravity Forms entries to Excel, CSV, or PDF and share them instantly with secure download links.

    • GravityMath

      GravityMath

      Perform advanced calculations on Gravity Forms entries to display totals, averages, or build custom calculators.

    • GravityRevisions

      GravityRevisions

      Track, compare, and restore changes made to Gravity Forms forms and entries with a full version history.

    • GravityMigrate

      GravityMigrate

      Migrate all Gravity Forms data, including forms, entries, Views, feeds, uploads, and more.

    • GravityBoard

      GravityBoard

      Manage projects with collaborative project management. Coordinate with your team and streamline your workflows.

  • Ideal For

    • Nonprofits
    • Startups
    • Education
    • Web Agencies
    • Developers
    • Government iconGovernment
    Explore All Use Cases

    Case studies

    • West Fork Schools
    • Princeton University
    • BrightLeaf Giving
    • Jacksonville Port Authority
    • National Severe Storms Lab
    • Leadpal
    • Mediebruket
    • Dragonfly
    View All Case Studies
  • Resources

    • Blog
    • Case studies
    • Support
    • Live Demos
    • Documentation
    • Developer docs
    • GravityKit Academy
    • GravityKit Live!

    Ultimate guides

    • How to use Gravity Forms
    • Editing Gravity Forms entries
    • Importing Gravity Forms entries
    • Exporting Gravity Forms entries
    • Displaying Gravity Forms entries
    • Gravity Forms conditional logic
    • Gravity Forms calculations
    View More Articles
  • Plugins

    • GravityView

      GravityView

      Bestseller

      Display Gravity Forms entries on the front-end of your site and build powerful web applications.

    • GravityImport

      GravityImport

      Trending

      Import entries from CSV files into Gravity Forms to transfer data, create new forms, or update existing entries.

    • GravityEdit

      GravityEdit

      Quickly edit Gravity Forms entries inline to save time, reduce clicks, and streamline your workflow.

    • GravityCharts

      GravityCharts

      Trending

      Turn Gravity Forms entries into interactive charts and graphs.

    • GravityActions

      GravityActions

      Update multiple Gravity Forms entries at once, send bulk emails, and streamline your workflow.

    • GravityCalendar

      GravityCalendar

      Turn Gravity Forms entries into dynamic calendars to showcase events, schedules, appointments, and more.

    • GravityExport

      GravityExport

      Export Gravity Forms entries to Excel, CSV, or PDF and share them instantly with secure download links.

    • GravityMath

      GravityMath

      Perform advanced calculations on Gravity Forms entries to display totals, averages, or build custom calculators.

    • GravityRevisions

      GravityRevisions

      Track, compare, and restore changes made to Gravity Forms forms and entries with a full version history.

    • GravityMigrate

      GravityMigrate

      Migrate all Gravity Forms data, including forms, entries, Views, feeds, uploads, and more.

    • GravityBoard

      GravityBoard

      Manage projects with collaborative project management. Coordinate with your team and streamline your workflows.

    GravityKit All Access

    Our complete Kit of essential tools for extending and enhancing Gravity Formsโ€”everything you need to build powerful web apps and workflows.

    Learn more
  • Ideal For

    • Nonprofits
    • Startups
    • Education
    • Web Agencies
    • Developers
    • Government iconGovernment
    Explore All Use Cases

    Case studies

    • West Fork Schools
    • Princeton University
    • BrightLeaf Giving
    • Jacksonville Port Authority
    • National Severe Storms Lab
    • Leadpal
    • Mediebruket
    • Dragonfly
    View All Case Studies

    How to build...

    • Property Management
    • Product Catalog
    • Fundraising Dashboard
    • Real Estate Directory
    • Document Library
    • Academic Journal
    • Volunteer Management
    • Meal Tracker
    View All Guides
  • Resources

    • Blog
    • Case studies
    • Support
    • Live Demos
    • Documentation
    • Developer docs
    • GravityKit Academy
    • GravityKit Live!

    ultimate guides

    • How to use Gravity Forms
    • Editing Gravity Forms entries
    • Importing Gravity Forms entries
    • Exporting Gravity Forms entries
    • Displaying Gravity Forms entries
    • Gravity Forms conditional logic
    • Gravity Forms calculations
    View More Articles
  • Pricing
  • About
0 items

Search

Results appear automatically as you type.
Loading results…

results found matching

    Sign in
    Buy

    Docs

    • Docs Home

    Gravity Forms Add-Ons

    • GravityView
    • GravityActions
    • GravityBoard
    • GravityCalendar
    • GravityCharts
    • GravityEdit
    • GravityExport
    • GravityImport
    • GravityMath
    • GravityMigrate
    • GravityRevisions
    • GF Widget for Elementor
    • GF Dynamic Lookup
    • GF Entry Tags
    • GF Event Field
    • GF Zero Spam
    • GravityExport Lite

    GravityView

    • Getting Started
    • View Setup
    • FAQ
    • Pre-Sale
    • Advanced
    • Common Problems
    • Customizing Your Views
    • Edit Entry
    • Entry Approval
    • Filter and Sort Results
    • Gravity Forms
    • Merge Tags
    • Roles and Capabilities
    • Search
    • Shortcodes
    • View Settings
    • WordPress Posts

    General Help

    • Account, Invoices, and Billing
    • License Related
    • Plugins and Settings
    • Contact
    • Docs Home
    • Gravity Forms Add-Ons

      • GravityView
      • GravityActions
      • GravityBoard
      • GravityCalendar
      • GravityCharts
      • GravityEdit
      • GravityExport
      • GravityImport
      • GravityMath
      • GravityMigrate
      • GravityRevisions
      • GF Widget for Elementor
      • GF Dynamic Lookup
      • GF Entry Tags
      • GF Event Field
      • GF Zero Spam
      • GravityExport Lite
    • GravityView

      • Getting Started
      • View Setup
      • FAQ
      • Pre-Sale
      • Advanced
      • Common Problems
      • Customizing Your Views
      • Edit Entry
      • Entry Approval
      • Filter and Sort Results
      • Gravity Forms
      • Merge Tags
      • Roles and Capabilities
      • Search
      • Shortcodes
      • View Settings
      • WordPress Posts
    • General Help

      • Account, Invoices, and Billing
      • License Related
      • Plugins and Settings
    • Contact

    GravityMath

    • Add calculations to blog posts
    • Calculating Survey fields totals based on their scoring
    • Calculations in GravityView
    • Can GravityMath be used inside a Gravity Forms form?
    • Can I use [gravitymath] with [gvlogic]?
    • Can I use [gravitymath] with dates and times?
    • Can I use [gravitymath] with Multiple Forms?
    • Debugging Calculations in GravityMโ€‹ath
    • Developer Hooks for GravityMath
    • Does GravityMath support the Polls Add-on?
    • Does GravityMath support the Survey Add-on?
    • GravityMath Calculation field
    • How to add field calculations to the table footer
    • How to Calculate the Sum of a Field in Gravity Forms
    • How to display summaries using a block, widget, or shortcode
    • How to enable duration calculations in Gravity Forms with GravityMath
    • How to perform Gravity Forms time calculations in GravityView using GravityMath
    • Math filters: How to target a specific field value with [gravitymath] filters
    • Nested calculations in GravityMath
    • Pricing fields calculation
    • Sum GravityMath values for today, a custom date range, or a rolling window
    • The [gravitymath] Shortcode
    • The {entry_count} Merge Tag in Math by GravityView
    • Using GravityMath inside a GravityView Custom Content field
    • When to use GravityMath and when to use GP Advanced Calculations
    • Home
    • Docs
    • GravityMath
    • Using GravityMath inside a GravityView Custom Content field

    Using GravityMath inside a GravityView Custom Content field

    Estimated reading: 5 minutes

    Updated on April 24, 2026

    When using the [gravitymath] ย ย shortcode inside a GravityView Custom Content field, you may encounter issues with merge tags being processed in the wrong order. This article explains the problem and provides a workaround.

    Understanding the Problem #

    GravityView processes merge tags in Custom Content fields before shortcodes run. This means any merge tags inside your [gravitymath] ย ย shortcode get replaced by GravityView before GravityMath ever sees them.

    Example Scenario: Sales Team Dashboard #

    Let’s say you have two forms:

    Form A (ID: 10) – Sales Reps

    • Field 1: Sales Rep Name
    • Field 2: Region
    • Field 3: Email

    Form B (ID: 20) – Orders

    • Field 5: Sales Rep Name (dropdown matching reps from Form A)
    • Field 6: Order Total
    • Field 7: Order Date

    You create a View using Form A to display your sales team. For each rep, you want to show how many orders they have in Form B.

    What you might try (and why it doesn’t work)

    In a Custom Content field, you add:

    Orders: [gravitymath scope="form" id="20" filter="filter_5={Sales Rep Name:1}"]{Order Total:6:count}[/gravitymath]

    Expected result: Each sales rep shows their order count.

    Actual result: The count is wrong or empty.

    Why? GravityView processes {Order Total:6:count} ย ย first. Since field 6 doesn’t exist in Form A (the View’s source), it fails. GravityMath never gets to process it.

    The Workaround #

    We need a way to tell GravityView to leave certain merge tags alone so GravityMath can process them. The workaround below uses an alternate syntax (tildes ~~ ย ย instead of curly braces {} ย ) to mark merge tags that should be handled by GravityMath.

    Step 1: Add the helper snippet

    Add this code to your site (where to add code):

    /**
     * Allows using ~Field:ID~ syntax in GravityMath shortcodes.
     * Prevents GravityView from processing these merge tags prematurely.
     * The snippet converts ~~ to {} right before GravityMath runs.
     */
    add_filter( 'gravityview/math/shortcode/before', function ( $formula ) {
        preg_match_all( '/~[^~]*?:(\d+(\.\d+)?|[a-z_]+)(:(.*?))?~/mi', $formula, $merge_tags, PREG_SET_ORDER );
    
        foreach ( $merge_tags as $merge_tag ) {
            $updated_merge_tag = str_replace( '~', '', $merge_tag[0] );
            $updated_merge_tag = sprintf( '{%s}', $updated_merge_tag );
            $formula = str_replace( $merge_tag[0], $updated_merge_tag, $formula );
        }
    
        return $formula;
    } );

    Step 2: Update your shortcode

    Wrap merge tags that reference the queried form (Form B) with tildes instead of curly braces:

    Before:

    Orders: [gravitymath scope="form" id="20" filter="filter_5={Sales Rep Name:1}"]{Order Total:6:count}[/gravitymath]

    After:

    Orders: [gravitymath scope="form" id="20" filter="filter_5={Sales Rep Name:1}"]~Order Total:6:count~[/gravitymath]

    Now each sales rep’s row correctly shows their order count from Form B.

    Which Syntax to Use #

    SyntaxProcessed byWhen to use
    {Field:ID} ย GravityView (first)The field is from the View’s form and you want its current value
    ~Field:ID~ ย GravityMath (after snippet runs)The field is from the queried form and GravityMath should process it

    In our example:

    • {Sales Rep Name:1} ย ย uses curly braces. This is from Form A (the View’s form). We want GravityView to replace it with the current rep’s name so it can filter Form B.
    • ~Order Total:6:count~ ย ย uses tildes. This is field 6 from Form B (the queried form). We need GravityMath to count it after applying the filter.

    More Examples #

    Counting filtered entries

    Count orders for the current sales rep:

    [gravitymath scope="form" id="20" filter="filter_5={Sales Rep Name:1}"]~Order Total:6:count~[/gravitymath]

    Summing filtered values

    Sum order totals for the current sales rep:

    [gravitymath scope="form" id="20" filter="filter_5={Sales Rep Name:1}"]~Order Total:6:sum~[/gravitymath]

    Calculating an average

    Average order value for the current sales rep:

    [gravitymath scope="form" id="20" filter="filter_5={Sales Rep Name:1}"]~Order Total:6:avg~[/gravitymath]

    Troubleshooting #

    Still not working?

    • Make sure the snippet is active on your site
    • Verify the field IDs match your actual forms
    • Check that the filter field (e.g., Sales Rep Name) has matching values in both forms
    • Remember: use {} ย ย for the View’s form fields, ~~ ย ย for the queried form’s fields

    If you’re still having trouble, contact our support team and we’ll be happy to help you set this up.

    Related Articles #

    • The [gravitymath] Shortcode
    • How to target a specific field value with [gravitymath] filters
    • Using the Custom Content Field
    • Where to put code samples
    Still stuck? How can we help?

    How can we help?

    "*" indicates required fields

    This field is for validation purposes and should be left unchanged.
    Replies will go to this email.
    How can we help?*
    My pre-sale question is related to...*
    My WordPress skills are....*
    My Gravity Forms skills are...*
    You will be shown articles from our documentation.
    Vous pouvez nous รฉcrire dans votre langue maternelle si cโ€™est plus facile pour vousโ€”nous nous occuperons de la traduction!
    Puedes escribirnos en tu idioma nativo si te resulta mรกs fรกcil; ยกnosotros nos encargamos de la traducciรณn!
    Sie kรถnnen uns in Ihrer Muttersprache schreiben, wenn das fรผr Sie einfacher ist โ€“ wir kรผmmern uns um die รœbersetzung!
    U kunt ons in uw moedertaal schrijven als dat gemakkelijker voor u is โ€” wij zorgen voor de vertaling!
    Du kan skrive til oss pรฅ ditt morsmรฅl hvis det er enklere for deg โ€” vi tar oss av oversettelsen!
    Du kan skriva till oss pรฅ ditt modersmรฅl om det รคr lรคttare fรถr dig โ€” vi tar hand om รถversรคttningen!
    Vocรช pode nos escrever em seu idioma nativo se for mais fรกcil para vocรช โ€” nรณs cuidaremos da traduรงรฃo!
    Puoi scriverci nella tua lingua madre se ti รจ piรน facile โ€” penseremo noi alla traduzione!
    Please provide as much detail as you're able; this helps us provide you with faster support.
    Drop files here or
    Accepted file types: jpg, jpeg, gif, png, tiff, pdf, bmp, zip, json, csv, xls, xlsx, Max. file size: 256 MB.
      Stay informed?

      Was this page helpful?

      Table Of Contents
      • Understanding the Problem
      • Example Scenario: Sales Team Dashboard
      • The Workaround
      • Which Syntax to Use
      • More Examples
      • Troubleshooting
      • Related Articles
      GravityKit
      • How to Build It
      • Pricing
      • Products
      • Our Team
      • Our Values
      • Work With Us
      • Coupons
      Support
      • Support
      • Contact
      • Documentation
      • Scope of Support
      • Brand Guidelines
      • Privacy Policy
      • Terms of Service (โ€œTermsโ€)
      About Us
      • GravityKit on Mastodon
      • GravityKit on Twitter
      • GravityKit Training Courses
      • GravityKit on Facebook
      • Join our Facebook Group
      • Facebook
      • Twitter
      Get notified of updates.

      Weโ€™re constantly improving GravityKit. Fill out your email below and weโ€™ll notify you anytime major updates drop.

      GravityKit is a Gravity Forms Certified Developer.

      Copyright ยฉ 2026, Katz Web Services, Inc.

      GravityKit and GravityView are registered trademarks of Katz Web Services, Inc.