Skip to content

Instantly share code, notes, and snippets.

@eclarrrk
Last active May 29, 2022 22:46
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eclarrrk/50d9ca07d21d8cf80fd0f71dd23fac19 to your computer and use it in GitHub Desktop.
Save eclarrrk/50d9ca07d21d8cf80fd0f71dd23fac19 to your computer and use it in GitHub Desktop.
Display Gravity Form entries into WordPress page template
<?php
/*
Official Gravity Forms documentation on get_entries() found here:
https://docs.gravityforms.com/api-functions/#get-entries
*/
/* Gravity Form ID. */
$form_id = '20';
/* Sorting options avalable but left blank for simplicity. */
$sorting = array();
/* Show entries that are active. Default search criteria gets entries in trash, as well. */
$search_criteria['field_filters'][] = array( 'key' => 'status', 'value' => 'Active' );
/* Gets total number of entries in a form that meet the search criteria. */
$total_count = GFAPI::count_entries( $form_id, $search_criteria );
/*
Gravity Forms documentation notes that optimum page size is 200 in order to prevent
database timeouts. If you are expecting lots more than 200 entires (I am planning
for up to 1000 entries) splitting the returned array may prevent it from happening.
Or not... I literally don't know!
This will print a maximum of 200 entries.
*/
$paging = array( 'offset' => 0, 'page_size' => 200 );
// $paging2 = array( 'offset' => 200, 'page_size' => 200 );
// $paging3 = array( 'offset' => 400, 'page_size' => 200 );
/* Include parameters from above */
$entries = GFAPI::get_entries( $form_id, $search_criteria, $sorting, $paging );
// $entries2 = GFAPI::get_entries( $form_id, $search_criteria, $sorting, $paging2 );
// $entries3 = GFAPI::get_entries( $form_id, $search_criteria, $sorting, $paging3 );
?>
<p>There are <?php echo $total_count; ?> entries from form <?php echo $form_id; ?></p>
<ul>
<!-- START ENTRIES LIST -->
<?php
foreach ($entries as $entry) {
$firstName = rgar($entry, '13.3');
$lastName = rgar($entry, '13.6');
?>
<li>
<?php echo $firstName; ?> <?php echo $lastName; ?>
</li>
<?php } ?>
<!-- END ENTRIES LIST -->
</ul>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment