I’m using the Gravity Forms API to return a list of entries. It almost works fine, with the only issue being that the start and end dates are being ignored.
$form_id = isset($_GET['form-id']) ? $_GET['form-id'] : '';
$form = GFAPI::get_form($form_id);
$start_date = isset($_GET['start-date']) ? $_GET['start-date'] : '';
$end_date = isset($_GET['end-date']) ? $_GET['end-date'] : '';
$entries = GFAPI::get_entries($form_id, array(
'status' => array('active'),
), array(), array(
'start_date' => $start_date,
'end_date' => $end_date,
'page_size' => 1000,
'offset' => 0
));
Instead of just returning items for the date range, all results are returned instead.
I’ve confirmed this by exporting all entries for the form and can see there are 170 entries all-time, and there are 15 entries between 2023-01-01 and 2023-03-01 and so only 15 entries should be returned based on this URL:
The dates in the query string are in the correct format.
What am I doing wrong?
2
Answers
Thanks. I got it working like this:
if you are sure that date format for start_date and end_date matches the format used in your Gravity Forms entries
eg if it is Y-m-d H:i:s make sure date format in the query string matches that, you can correct the format like the following
also your $_GET[‘start-date’] may not be getting populated I mean isset returns false ( server php settings ), to check that you can change flowing to
to
so if isset($_GET[‘start-date’]) returns false it will set the date.
you can turn the $_GET population turned on via register_globals in your php.ini file (this issue is common on NginX servers)
remember Y-m-d H:i:s format is what I assumed and you have to check the format used in your Gravity Forms entries.