Everything You Need to Know About Gravity Forms Database Structure

Everything you need to know about the database structure of Gravity Forms, a critical plugin for dynamic, interactive websites powered by WordPress today. Understand the database structure, and how the plugin handles data in the backend.

  1. Gravity Forms SQL Tables
    1. Form Data
    2. Entries Data
    3. Add-On Data
  2. Where are these SQL Tables stored?
  3. Sample SQL Queries
    1. All entry values for a form
    2. One row per entry, with specific fields as columns
    3. Entries where a field matches a value
    4. Entry counts by form and status
    5. Field IDs and labels for a form
  4. Forcing Gravity Forms Database Updates
  5. Integrate Gravity Forms with a Database
  6. Final Thoughts

Most of the time, you never need to think about where Gravity Forms keeps its data. But when you’re debugging a broken update, building a custom report, or answering a GDPR request, knowing the tables matters.

This guide covers each Gravity Forms table, explains where your entry data actually lives, and includes ready-to-run SQL queries for the things people most often need.

Gravity Forms SQL Tables

The table names below assume your site uses the default wp_ table prefix. If yours uses a different prefix, substitute it. Every Gravity Forms table also carries its own gf_ prefix.

The tables fall into three groups: forms, entries, and add-ons. Anything created through the Gravity Forms REST API ends up in these same tables.

Form Data

The basic information about a form is stored in wp_gf_form. That includes the form title, creation date, and whether the form is active or trashed. The full form configuration, including fields, labels, confirmations, and notifications, is stored as JSON in wp_gf_form_meta. View counts are stored in wp_gf_form_view. Each row in the meta and view tables links back to a single form in wp_gf_form.

Entries Data

Each submission creates one row in wp_gf_entry. That row holds the entry’s properties, not its field values: the form it belongs to, created and updated dates, the user who submitted it, IP, source URL, status (active, spam, or trash), and payment details if applicable. See the Entry Object for the full list. Did you know you can edit entries on the front end too?

The field values live in wp_gf_entry_meta. Each value is its own row, keyed by entry_id, with the field ID in meta_key and the submitted value in meta_value. Multi-input fields store one row per input using a decimal ID. For example, a Name field with ID 1 stores first name as 1.3 and last name as 1.6. Add-ons also store their own entry data here, under non-numeric keys.

Field labels are not stored with entries. They live in the form’s JSON configuration (display_meta in wp_gf_form_meta), so a raw query returns field IDs, not labels.

Entry notes go in wp_gf_entry_notes. Partial submissions from Save and Continue go in wp_gf_draft_submissions until the user completes the form.

Worth knowing…

Every entry has a status property, like active, spam, or trash. If you’d rather not delete old entries, our free Entry Archive plugin adds an archived status, so you can clear them from view without touching the underlying data.

Add-On Data

Gravity Forms creates three tables to support its add-ons. wp_gf_addon_feed stores each add-on feed’s configuration, such as a Stripe or Mailchimp feed, and which form it belongs to.

If an add-on processes payments, the wp_gf_addon_payment_transaction and wp_gf_addon_payment_callback tables store the transaction and callback details, respectively.

Where are these SQL Tables stored?

The tables live in the same MySQL or MariaDB database as the rest of your WordPress site. To browse them, use phpMyAdmin (most hosts include it) or the MySQL command line. If you have WP-CLI, wp db query runs SQL directly against your site’s database.

Sample SQL Queries

These queries assume the default wp_ prefix and a form with ID 1. Change both to match your site, along with any field IDs. Treat them as read-only. To create or update entries, use the GFAPI instead of writing to these tables directly.

All entry values for a form

SELECT e.id AS entry_id, e.date_created, m.meta_key AS field_id, m.meta_value
FROM wp_gf_entry e
JOIN wp_gf_entry_meta m ON m.entry_id = e.id
WHERE e.form_id = 1
  AND e.status = 'active'
  AND m.meta_key REGEXP '^[0-9.]+$'  -- field values only, skips add-on meta
ORDER BY e.id, m.meta_key + 0;

One row per entry, with specific fields as columns

SELECT e.id AS entry_id, e.date_created,
  MAX(CASE WHEN m.meta_key = '1.3' THEN m.meta_value END) AS first_name,
  MAX(CASE WHEN m.meta_key = '1.6' THEN m.meta_value END) AS last_name,
  MAX(CASE WHEN m.meta_key = '2'   THEN m.meta_value END) AS email
FROM wp_gf_entry e
JOIN wp_gf_entry_meta m ON m.entry_id = e.id
WHERE e.form_id = 1 AND e.status = 'active'
GROUP BY e.id, e.date_created
ORDER BY e.date_created DESC;

Entries where a field matches a value

SELECT e.id, e.date_created
FROM wp_gf_entry e
JOIN wp_gf_entry_meta m ON m.entry_id = e.id
WHERE e.form_id = 1
  AND m.meta_key = '2'
  AND m.meta_value LIKE '%@example.com';

Entry counts by form and status

SELECT f.id, f.title, e.status, COUNT(e.id) AS entries
FROM wp_gf_form f
LEFT JOIN wp_gf_entry e ON e.form_id = f.id
GROUP BY f.id, f.title, e.status
ORDER BY f.id;

Field IDs and labels for a form

This one requires MySQL 8.0+ or MariaDB 10.6+.

SELECT jt.field_id, jt.label, jt.type
FROM wp_gf_form_meta fm,
  JSON_TABLE(fm.display_meta, '$.fields[*]' COLUMNS (
    field_id INT          PATH '$.id',
    label    VARCHAR(255) PATH '$.label',
    type     VARCHAR(50)  PATH '$.type'
  )) jt
WHERE fm.form_id = 1;

A few fields need extra handling. Checkbox fields store one row per checked choice. List fields store serialized arrays. Multi-file upload fields store a JSON array of URLs.

Forcing Gravity Forms Database Updates

With the release of Gravity Forms 2.3, several tables were deprecated and should not be used. Future updates may also lead to changes in the database structure. Therefore, when you update the Gravity Forms plugin, you may encounter an error in the plugin due to the failure in the database modification.

Gravity Forms has a feature to manually run the database modification script after you have updated the plugin. In the WordPress admin dashboard, select the System Status option under the Forms menu. In the Database section, choose the option to “Re-run database upgrade” to port your database tables from the old structure to create new tables. As this process involves changing tables in your database directly, it is a good idea to back up your database in case the process fails and corrupts the plugin.

Integrate Gravity Forms with a Database

If you want to use database data in your forms, rather than just look at it, GP Populate Anything can populate fields and choices directly from any table in your WordPress database. It can also pull from other Gravity Forms entries. That covers things like a dropdown built from a custom table, or a form prefilled from a previous submission, with no SQL required.

To get entry data out of WordPress for reporting, Gravity Forms Google Sheets syncs entries to a spreadsheet automatically. From there, it connects to Looker Studio, BigQuery, and other tools.

Final Thoughts

Gravity Forms keeps form configuration in wp_gf_form and wp_gf_form_meta, entry properties in wp_gf_entry, and the submitted values themselves in wp_gf_entry_meta. Once you know that split, the queries above cover most reporting and debugging needs. When you want that data working inside your forms instead, Populate Anything handles it without SQL.

You need Gravity Perks to get the full power of Gravity Forms! Buy Gravity Perks today to all of our galactic Gravity Forms plugins!

Comments

    1. Samuel Bassah
      Samuel Bassah Staff May 19, 2021 at 6:44 am

      Hi CV,

      Nested Form entries are stored just like normal Gravity Forms entries. So yes, it also applies to Nested Forms.

      Best,

  1. NB
    NB January 13, 2021 at 12:32 am

    Ryan, would be great if you threw in some sample MySql queries – e.g. show me all the entries (field names and entry values) for a specific form, etc.

    Reply
    1. Ryan Donovan
      Ryan Donovan January 13, 2021 at 10:02 am

      Hello There, Thank you so much for the recommendation. We have noted this and may add this as we update our documentation. Thank you so much again!

  2. Jack
    Jack May 28, 2020 at 12:50 pm

    Thanks I am looking for the database record where the chosen currency is stored it must be in the database and not on php level I think that because I have a multi/networked site with for each subsites own currencies

    Reply
    1. Ryan Donovan
      Ryan Donovan May 28, 2020 at 2:38 pm

      Hey Jack, Just confirmed with the development team and GFCommon::get_currency() will provide them with the current currency that Gravity Forms is using.That’s a PHP function/method straight from Gravity Forms. Something to note is it does pull the rg_gforms_currency option in the wp_options table on the database if it’s set.

  3. jack Schneider
    jack Schneider May 28, 2020 at 5:21 am

    It is a nice description of the database usages but I mis the place where the gravity options are stored in the database probably in the wp_options table but I can not find them. I need that because with the default currency must be filled in and we have a lot of subsites.

    Gravity forms has been update and somtimes the currency is not find but form execution crashes when currency is empty. even when there is no currency field on the form.

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

  • Trouble installing this snippet? See our troubleshooting tips.
  • Need to include code? Create a gist and link to it in your comment.
  • Reporting a bug? Provide a URL where this issue can be recreated.

By commenting, I understand that I may receive emails related to Gravity Wiz and can unsubscribe at any time.