gf_entries_shortcode.php

Gravity Forms Display Entries Shortcode

This WordPress file contains a shortcode that allows users to display entries from a specified Gravity Form in a structured table format. It uses the Gravity Forms API to retrieve the entries and then generates an HTML table to present them on the site.

<?php add_shortcode("display_gf_entries", "display_gravity_forms_entries"); function display_gravity_forms_entries($atts) { $defaults = [ "id" => "", ]; $atts = shortcode_atts($defaults, $atts); if (class_exists("GFAPI")) { $entries = GFAPI::get_entries($atts["id"]); if (is_wp_error($entries)) { return "An error occurred while retrieving entries:"; } elseif (empty($entries)) { return "No entries found for the form id:"; } else { $output = "<table><thead><tr><th>ID</th><th>Date</th><th>Status</th></tr></thead><tbody>"; foreach ($entries as $entry) { foreach ($entry as $key => $value) { if ( !in_array( $key, ["id", "date_created", "status", "form_id"], true ) ) { $output .= "<td>" . $value . "</td>"; } } $output .= "</tr>"; } $output .= "</tbody></table>"; return $output; } } else { return "Gravity Forms API does not exist."; } } ?>

Frequently Asked Questions

This shortcode is designed to display entries from a specified Gravity Form in a tabular format on a WordPress website.