GravityKit icon

Black Friday Pro starts November 23.

Join the list for early access to the deals.

Join the List

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 Pro

      GravityView Pro

      Bestseller

      Get Live Filters, Maps, DataTables, the Advanced Elementor Widget and every other Pro feature to build the app your process needs.

    • GravityView

      GravityView

      Trending

      Display Gravity Forms entries on the frontend 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, PDF, or Google Sheets, then share them with secure links or deliver them to cloud storage on a schedule.

    • 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 between sites, including forms, entries, settings, Views, feeds, and file uploads, and import forms from other form plugins.

    • GravityBoard

      GravityBoard

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

    • GravitySearch

      GravitySearch

      Search Gravity Forms entries across every form from one screen.

  • Ideal For

    • Nonprofits
    • Web Agencies
    • Education
    • Developers
    • Small Businesses
    • Startups
    Explore All Use Cases

    Case studies

    • Be There Local
    • Killer Shorts
    • West Fork Schools
    • Princeton University
    • BrightLeaf Giving
    • Jacksonville Port Authority
    • National Severe Storms Lab
    • Leadpal
    View All Case Studies
  • Resources

    • Blog
    • Case studies
    • Newsletter
    • GravityKit vs competitors
    • Live Demos
    • Documentation
    • Developer docs
    • GravityKit Academy

    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
  • Support
  • Pricing
  • Plugins

    • GravityView Pro

      GravityView Pro

      Bestseller

      Get Live Filters, Maps, DataTables, the Advanced Elementor Widget and every other Pro feature to build the app your process needs.

    • GravityView

      GravityView

      Trending

      Display Gravity Forms entries on the frontend 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, PDF, or Google Sheets, then share them with secure links or deliver them to cloud storage on a schedule.

    • 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 between sites, including forms, entries, settings, Views, feeds, and file uploads, and import forms from other form plugins.

    • GravityBoard

      GravityBoard

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

    • GravitySearch

      GravitySearch

      Search Gravity Forms entries across every form from one screen.

    View All Products

    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
    • Web Agencies
    • Education
    • Developers
    • Small Businesses
    • Startups
    Explore All Use Cases

    Case studies

    • Be There Local
    • Killer Shorts
    • West Fork Schools
    • Princeton University
    • BrightLeaf Giving
    • Jacksonville Port Authority
    • National Severe Storms Lab
    • Leadpal
    View All Case Studies

    How to build...

    • Client Portal
    • AI-Built Directory
    • Conference Website
    • WordPress CRM
    • Admin Dashboard
    • Inventory Management
    • Vendor Portal
    • Document Library
    View All Guides
  • Resources

    • Blog
    • Case studies
    • Newsletter
    • GravityKit vs competitors
    • Live Demos
    • Documentation
    • Developer docs
    • GravityKit Academy

    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
  • Support
  • Pricing
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
    • GravityRevisions
    • GravitySearch
    • GF Widget for Elementor
    • GF Dynamic Lookup
    • GF Entry Tags
    • GF Event Field
    • GravityExport Lite
    • GF Zero Spam
    • GravityMigrate

    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
    • Agency accounts
    • Contact
    • Docs Home
    • Gravity Forms Add-Ons

      • GravityView
      • GravityActions
      • GravityBoard
      • GravityCalendar
      • GravityCharts
      • GravityEdit
      • GravityExport
      • GravityImport
      • GravityMath
      • GravityRevisions
      • GravitySearch
      • GF Widget for Elementor
      • GF Dynamic Lookup
      • GF Entry Tags
      • GF Event Field
      • GravityExport Lite
      • GF Zero Spam
      • GravityMigrate
    • 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
      • Agency accounts
    • Contact

    GravityMath

    • Add calculations to blog posts
    • Calculate the time between two dates with [gravitymath]
    • Calculating totals of Survey fields from their scores
    • Calculating with pricing fields in a View
    • Calculations in GravityView
    • Can GravityMath be used inside a Gravity Forms form?
    • Can I use [gravitymath] with [gvlogic]?
    • Can I use [gravitymath] with Multiple Forms?
    • Debugging calculations in GravityMath
    • 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: targeting a specific field value with [gravitymath]
    • Nested calculations in GravityMath
    • Sum GravityMath values for today, a custom date range, or a rolling window
    • The [gravitymath] shortcode
    • The {entry_count} merge tag in GravityMath
    • Using GravityMath inside a GravityView Custom Content field
    • When to use GravityMath and when to use GP Advanced Calculations
    • Home
    • Docs
    • GravityMath
    • Developer hooks for GravityMath

    Developer hooks for GravityMath

    Estimated reading: 7 minutes

    Updated on November 6, 2026

    Developers can change how GravityMath calculates and what it prints with the filters and actions on this page. Each one goes in a code snippet on your site. The GravityMath developer documentation on gravitykit.dev has the parameters of every hook on this page and the file each one is in.

    Live totals in DataTables Views #

    With GravityMath 2.14.0 and DataTables 3.15.0 or newer, a [gravitymath scope="visible"] total in a Custom Content widget of a DataTables View follows the table. Each time the table shows other rows, your site works out the total again over the rows on screen. The [gravitymath] shortcode explains the visible scope. The filters below change this for one View or for all of them.

    gk/gravitymath/datatables/visible/live

    Live totals are on by default. When this filter returns false for a View, the totals in its Custom Content widgets print nothing.

    /**
     * Turns off live totals in the DataTables View with ID 123.
     *
     * @param bool     $enabled Whether scope="visible" totals follow
     *                          the table.
     * @param \GV\View $view    The View.
     *
     * @return bool
     */
    add_filter(
        'gk/gravitymath/datatables/visible/live',
        function ( $enabled, $view ) {
            if ( 123 === (int) $view->ID ) {
                return false;
            }
    
            return $enabled;
        },
        10,
        2
    );

    gk/gravitymath/datatables/visible/max-tokens

    One table updates up to 20 totals each time it draws. This filter changes that number, and the totals past it print nothing.

    /**
     * Lets the DataTables View with ID 123 update up to 30 totals
     * on each draw.
     *
     * @param int      $max  The most totals one table updates. Default: 20.
     * @param \GV\View $view The View.
     *
     * @return int
     */
    add_filter(
        'gk/gravitymath/datatables/visible/max-tokens',
        function ( $max, $view ) {
            if ( 123 === (int) $view->ID ) {
                return 30;
            }
    
            return $max;
        },
        10,
        2
    );

    gk/gravitymath/datatables/visible/hidden-fields

    By default, a total prints nothing when it reads a field that the table doesn’t show as a column. A visitor who shows one row at a time could otherwise read each row’s value of that field from the total. This filter lets such totals follow the table. It receives the IDs of the fields the total reads that aren’t columns, so you can allow only the fields that are safe to show.

    /**
     * Lets totals in the DataTables View with ID 123 read field 8,
     * which the table does not show as a column.
     *
     * @param bool     $allowed Whether the totals follow the table.
     *                          Default: false.
     * @param \GV\View $view    The View.
     * @param string[] $fields  The field IDs the totals read that the table
     *                          does not show.
     *
     * @return bool
     */
    add_filter(
        'gk/gravitymath/datatables/visible/hidden-fields',
        function ( $allowed, $view, $fields ) {
            $other_fields = array_diff( $fields, array( '8' ) );
    
            if ( 123 === (int) $view->ID && array() === $other_fields ) {
                return true;
            }
    
            return $allowed;
        },
        10,
        3
    );

    gk/gravitymath/datatables/visible/max-rows

    In a Preloaded (Client-side) table, a total covers up to 1,000 rows by default, or the largest number in the View’s rows-per-page menu if that is higher. When a visitor shows more rows than that, such as with All in the Show entries menu, the total goes blank. This filter changes the limit. It doesn’t affect the Ajax (Server-side) mode.

    /**
     * Lets totals in the Preloaded DataTables View with ID 123 cover up to
     * 5,000 rows.
     *
     * @param int      $max  The most rows a total covers. Default: 1000, or
     *                       the largest number in the rows-per-page menu.
     * @param \GV\View $view The View.
     *
     * @return int
     */
    add_filter(
        'gk/gravitymath/datatables/visible/max-rows',
        function ( $max, $view ) {
            if ( 123 === (int) $view->ID ) {
                return 5000;
            }
    
            return $max;
        },
        10,
        2
    );

    Note: Not sure where to add the code? See Where to put code samples.

    Shortcode output and formulas #

    This prints 0 where a [gravitymath] shortcode has no result, such as a formula GravityMath can’t work out:

    /**
     * Prints 0 where a [gravitymath] shortcode has no result.
     *
     * @param string $result The shortcode output.
     *
     * @return string|int
     */
    add_filter( 'gravityview/math/shortcode/output', function ( $result ) {
        return ( '' === $result ) ? 0 : $result;
    } );
    HookWhat it changes
    gravityview/math/shortcode/outputThe shortcode’s result, before it’s printed.
    gravityview/math/shortcode/beforeThe formula, before GravityMath works it out. Using GravityMath inside a GravityView Custom Content field uses it to keep merge tags for GravityMath.
    gravityview/math/shortcode/default_valueThe default_value parameter, the number that replaces an empty field value.
    gravityview/math/precisionThe most decimal places a result can have, 16 by default.
    gravityview/math/thousands_sepThe thousands separator GravityMath removes from field values before it calculates. By default, it’s the separator of the site’s language.
    gravityview/math/sanitizeThe formula after GravityMath cleans it.
    gravityview/math/init (action)Runs when the math engine starts, so you can add your own functions and constants.

    Table footer calculations #

    HookWhat it changes
    gravityview/math/table_footer_calculation/math_shortcodeThe [gravitymath] shortcode that GravityMath builds for a column’s result.
    gravityview/math/table_footer_calculation/calculation_resultA column’s result, before it’s shown.
    gravityview/math/table_footer_calculation/format_duration_field_calculation_resultHow a total of time durations is shown.
    gk/gravitymath/table-footer-calculation/supported-fields-schemaWhich field types offer a calculation, and which calculation types each one offers.

    How to add field calculations to the table footer explains the settings these hooks work on.

    Totals over many entries #

    HookWhat it changes
    gravityview/math/entries/visibleThe entries a scope="visible" total covers.
    gravityview/math/aggregate_data/modify_field_valueGets each field value of a scope="view" or scope="visible" total before it’s added up. For an entry without a value, that value is an empty string.
    gk/gravitymath/scope/form/transform-meta-valueThe SQL that turns a saved value into a number for scope="form" totals. By default, it casts the value to a decimal.
    gk/gravitymath/use_db_cacheWhether GravityMath caches the results of totals over a form’s entries.

    An entry without a value in the field reaches the filter as an empty string, and GravityMath leaves it out of averages, minimums, and maximums. Before GravityMath 2.14.1, fields such as Radio Buttons and Option fields passed 0 instead. This counts those entries as 0 for field 7 of form 97, as default_value="0" does in a single shortcode. Totals with scope="form" don’t run this filter.

    /**
     * Counts entries without a value in field 7 of form 97 as 0,
     * so averages divide by every entry and the lowest value can be 0.
     *
     * @param float|string $value          The value GravityMath calculates
     *                                     with. An empty string when the
     *                                     entry has no value.
     * @param string       $original_value The value saved in the entry.
     * @param string       $field_id       The field or input ID.
     * @param array        $entry          The entry.
     * @return float|string
     */
    add_filter(
        'gravityview/math/aggregate_data/modify_field_value',
        function ( $value, $original_value, $field_id, $entry ) {
            $form_id = (int) $entry['form_id'];
    
            if ( 97 === $form_id && '7' === (string) $field_id ) {
                return '' === $value ? 0 : $value;
            }
    
            return $value;
        },
        10,
        4
    );

    Summaries #

    HookWhat it changes
    gk/gravitymath/summary/entriesThe entries a summary calculates over.
    gk/gravitymath/summary/dataThe rows of a summary table, before it’s shown.
    gk/gravitymath/summary/headersThe column headings of a summary table.
    gk/gravitymath/summary/templateThe template file that prints a summary table.

    How to display summaries using a block, widget, or shortcode explains summaries.

    Notices and debugging #

    HookWhat it changes
    gravityview/math/accuracy_messageThe warning notice, “* Results may not be accurate.” by default.
    gravityview/math/no_results_messageThe error notice, “** No Results Currently Available.” by default.
    gravityview/math/admin_noticeThe line that tells administrators why they can see a notice.
    gravityview/math/suppress_errorsWhether notices are hidden. Return true to hide them.
    gravityview/math/debugWhether a shortcode is added to the debug report.
    gravityview/math/debug_messageThe text of each message in the debug report.

    Debugging calculations in GravityMath explains the notices and the debug report.

    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.
      Get better at Gravity Forms every Friday

      Was this page helpful?

      Table Of Contents
      • Live totals in DataTables Views
      • Shortcode output and formulas
      • Table footer calculations
      • Totals over many entries
      • Summaries
      • Notices and debugging
      GravityKit
      • How to Build It
      • GravityKit vs competitors
      • Pricing
      • Products
      • Our Team
      • Our Values
      • Work With Us
      • Partner Directory
      • Coupons
      Support
      • Support
      • Contact
      • Documentation
      • Scope of Support
      • Brand Guidelines
      • Brand Kit
      • Privacy Policy
      • Terms of Service (“Terms”)
      I am a...
      • Nonprofit
      • Web agency
      • Small business owner
      • Web developer
      • Educational institution
      • WordPress freelancer
      • Startup founder
      • One-person agency
      Get notified of updates.

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

      See past editions
      • Facebook
      • Twitter
      • Mastodon
      GravityKit is a Gravity Forms Certified Developer.

      Copyright © 2026, Katz Web Services, Inc.

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