Created
March 16, 2018 16:19
-
-
Save kenmasters/dd5845cea01856f861fe621530e040c2 to your computer and use it in GitHub Desktop.
List gravityform entries using GFAPI class + pagination
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# http://inlinedocs.gravityhelp.com/class-GFAPI.html | |
# https://docs.gravityforms.com/getting-started-with-the-gravity-forms-api-gfapi/ | |
# working code | |
# notes: we are to going to lists submitted entries of the current loggedin user. | |
$form_ids = [19, 20, 21, 22, 23, 24, 25, 26]; // accepts single or array of form id's. | |
$search_criteria = array( | |
'field_filters' => array( | |
'mode' => 'any', | |
array( | |
'key' => 'created_by', | |
'value' => get_current_user_id() | |
) | |
) | |
); | |
$pagination_links = ''; | |
$page_size = 5; | |
$current_page = max( 1, $_REQUEST['pagenum'] ); | |
$offset = ($current_page - 1) * $page_size; | |
$sorting = []; | |
$paging = ['offset' => $offset, 'page_size' => $page_size]; | |
$total_count = 0; | |
$orders = GFAPI::get_entries( $form_ids , $search_criteria, $sorting, $paging, $total_count ); | |
$total_pages = ceil( $total_count / $page_size ); | |
echo 'Total ' . $total_count; | |
echo '<br/>'; | |
echo 'Page Size ' . $page_size; | |
echo '<br/>'; | |
echo 'Total Pages ' . $total_pages; | |
echo '<br/>'; | |
echo 'Current Page ' . $current_page; | |
// Pagination Links | |
if ( $total_pages > 1 ) { | |
$pagination_links = '<div class="pagination pull-right">'; | |
$pagination_links .= paginate_links([ | |
'base' => @add_query_arg('pagenum','%#%'), | |
'format' => '&pagenum=%#%', | |
'current' => $current_page, | |
'total' => $total_pages, | |
'prev_next' => false | |
]); | |
$pagination_links .= '</div>'; | |
} | |
?> | |
<div class="container-fluid"> | |
<div class="row"> | |
<h2>Sub Agent: <?=$user->user_login;?></h2> | |
<div class="table-responsive"> | |
<table class="table table-striped table-hover widefat"> | |
<thead> | |
<tr> | |
<th colspan="2" class="info">List of Orders</th> | |
</tr> | |
<tr> | |
<th>Date of Order</th> | |
<th>Quantity of Order</th> | |
</tr> | |
</thead> | |
<tbody> | |
<?php if ( $orders ) { | |
foreach ($orders as $key => $value) { ?> | |
<tr> | |
<td><?=date('Ymd H:i', strtotime($value['date_created']))?></td> | |
<td>1</td> | |
</tr> | |
<?php } | |
} else { ?> | |
<tr class="warning"> | |
<td colspan="2">No orders found</td> | |
</tr> | |
<?php } ?> | |
</tbody> | |
<tfoot> | |
<tr> | |
<th>Date of Order</th> | |
<th>Quantity of Order</th> | |
</tr> | |
</tfoot> | |
</table> | |
</div> <!-- #table-responsive --> | |
<!-- Pagination --> | |
<?=$pagination_links;?> | |
<!-- Pagination --> | |
</div> <!-- .row --> | |
</div> <!-- .container-fluid --> |
Glad it help😊
@kenmasters Thank you for posting this!
Update: I have got a solution to what I described below. Sorry for the interruption!
I have a form that could have anywhere between 200-1000+ entries here in the coming weeks (it is an order form) and I need to get the quantity for every product field and add it up for each product across every entry.
Is there a way I could do something similar with the page size and pagination while keeping track of quantities? I have the code that I currently have listed below. I know that I am going to run into slowness if I set a page size of 1000.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Supper helpful thanks for sharing!