📜  GFAPI::get_entries (1)

📅  最后修改于: 2023-12-03 15:00:54.646000             🧑  作者: Mango

GFAPI::get_entries

Introduction:

GFAPI::get_entries is a function provided by the Gravity Forms API for retrieving form entries. Gravity Forms is a popular WordPress plugin that allows users to create and manage forms on their websites. The API provides a way to interact with forms and entries programmatically, enabling developers to integrate Gravity Forms functionality into their own applications.

Syntax:

GFAPI::get_entries( $form_id = 0, $search_criteria = array(), $sorting = null, $paging = null, $total_count = null );

Parameters:

  • $form_id (integer) - (optional) The ID of the form to retrieve entries from. Defaults to 0, which returns all entries from all forms.
  • $search_criteria (array) - (optional) An array of criteria to filter the entries. Defaults to an empty array.
  • $sorting (array) - (optional) An array specifying the sorting of the entries. Defaults to null, which results in no specific sorting.
  • $paging (array) - (optional) An array specifying the paging of the entries. Defaults to null, which returns all entries without pagination.
  • $total_count (integer) - (optional) The total count of entries matching the search criteria. Defaults to null, which does not include the total count in the result.

Return Value:

The function returns an array of entry objects representing the form entries that match the provided search criteria. Each entry object contains various properties corresponding to the fields in the form.

Example return value in Markdown format:

```php
array(
    [0] => GravityFormsEntry Object
        (
            [id] => 1
            [form_id] => 1
            [date_created] => 2021-01-01 12:00:00
            [created_by] => 1
            [status] => active
            [ip] => 127.0.0.1
            ...
        ),
    [1] => GravityFormsEntry Object
        (
            [id] => 2
            [form_id] => 1
            [date_created] => 2021-01-02 15:30:00
            [created_by] => 2
            [status] => active
            [ip] => 127.0.0.1
            ...
        ),
    ...
)

**Usage:**

To retrieve all form entries for a specific form, you can use the `GFAPI::get_entries` function without any parameters:

```php
$entries = GFAPI::get_entries( $form_id );

To filter the entries based on specific criteria, you can provide the $search_criteria parameter as an array. For example, to retrieve all entries where the field with the input ID 3 has a value of "John Doe", you can use the following code:

$search_criteria = array(
    'field_filters' => array(
        array(
            'key' => '3', // Input ID of the field
            'value' => 'John Doe',
        ),
    ),
);

$entries = GFAPI::get_entries( $form_id, $search_criteria );

Note:

  • The GFAPI::get_entries function can be used with or without global entry permissions. If the user does not have access to the form, the function will return an empty array.
  • Make sure to include the necessary files and initialize Gravity Forms before using the GFAPI::get_entries function.
  • Using the API functions correctly requires a good understanding of the Gravity Forms data structure and available options. Documentation and examples provided by Gravity Forms can be useful in gaining a deeper understanding of the API.