skip to Main Content

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:

https://example.com/wp-admin/admin.php?start-date=2023-01-01&end-date=2023-03-01&page=gravity-stuff&form-id=1

The dates in the query string are in the correct format.

What am I doing wrong?

2

Answers


  1. Chosen as BEST ANSWER

    Thanks. I got it working like this:

    'status' => array('active'),
    'field_filters' => array(
        array(
            'key' => 'date_created',
            'operator' => 'between',
            'value' => array($start_date, $end_date),
        ),
    ),
    ), array(), array(
        'page_size' => 1000
    ));
    

  2. 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

    $start_date = date('Y-m-d 00:00:00', strtotime($start_date)); 
    $end_date = date('Y-m-d 23:59:59', strtotime($end_date));     
    

    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

    $start_date             = isset($_GET['start-date']) ? $_GET['start-date'] : '';
    $end_date               = isset($_GET['end-date']) ? $_GET['end-date'] : '';
    

    to

    $start_date             = isset($_GET['start-date']) ? $_GET['start-date'] : '2023-01-01  00:00:00';
    $end_date               = isset($_GET['end-date']) ? $_GET['end-date'] : '2023-03-01  23:59:59';
    

    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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search