bookmark_borderManaging Entries with WP-CLI

By using the CLI add-on for Gravity Forms, you can easily manipulate entries using the command line. This article will show you the various commands available to you for managing entries.

Creating Entries

Using JSON

Example

Accepts JSON:

wp gf entry create $(wp entry get 3 --raw --format=json)

Parameters

wp gf entry create <entry-json>
  • entry-json
    JSON containing the entry information. This can either be raw JSON surrounded by single quotes, or the path to a file.

    Example JSON

      {
       "id":"1",
       "form_id":"1",
       "date_created":"2016-03-22 19:13:19",
       "is_starred":0,
       "is_read":0,
       "ip":"192.168.50.1",
       "source_url":"http:\/\/local.wordpress.dev\/?gf_page=preview&id=1",
       "post_id":null,
       "currency":"USD",
       "payment_status":null,
       "payment_date":null,
       "transaction_id":null,
       "payment_amount":null,
       "payment_method":null,
       "is_fulfilled":null,
       "created_by":"1",
       "transaction_type":null,
       "user_agent":"Mozilla\/5.0 (Macintosh; Intel Mac OS X 10_11_1) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/48.0.2564.116 Safari\/537.36",
       "status":"active",
       "1":"Third Choice",
       "2":"This is text content"
      }
      

  • form-id
    The form ID that the new entry should be associated with.

Using Field/Value arguments

Example

wp gf entry create 1 --field_1=ABC --field_2=test@test.com --field_3=1234 --field_4=Hello --field_5.3=John --field_5.6=Doe

Parameters

  • form-id
    The ID of the form that the new entry should be associated with.

  • –field=value
    This allows you to associate values with specific fields within the entry. The field will be the the field ID, for example, field_4.
    The value will be the information that you would like to place within it, such as a text string.
    For example:

      --field_4=ABC
      

Deleting Entries

Example

wp gf entry delete 5 --force

Parameters

  • entry-id
    The ID of the entry to delete

  • –force
    Skips the trash and permanently deletes the entry.

Duplicating Entries

Example

wp gf entry duplicate 5 --count=3

Parameters

  • entry-id
    The ID of the entry you want to duplicate.

  • –count=
    The number of time you want the entry to be duplicated.

Editing Entries

Example

wp gf entry edit 5

Parameters

  • entry-id
    The ID of the entry to be edited.

Exporting Entries

Example

wp gf entry export 5 myexport.json --dir=mydir --format=json

Parameters

  • form-id
    The ID of the form that you want to entries export.

  • filename
    The name of the export file you want to create. Defaults to form_title-date.format

  • –dir=
    The directory that you want to place the export file in. Defaults to the current working directory.

  • –format=
    Defines the format that the entry export should be in. Accepted values are csv or json. Defaults to CSV.

Returning Entries

Example

wp gf entry get 5 --format=json --raw

Parameters

  • entry-id
    The ID of the entry to be obtained.

  • –format=
    The format that the entry will be displayed in. Accepts table and json. Defaults to json.

  • –raw
    Displays the raw fields and values without formatting. This is best used as input for the create command.

Importing Entries

Examples

wp gf entry import 5 /path/to/file.json

Parameters

  • form-id
    The ID of the form that the entries are being imported into.

  • file
    The path to the file containing the entry data, formatted in JSON.

Listing Entries

Example

wp gf entry list 5 --status=active

Parameters

  • form-id
    The ID of the form from which entries should be listed.

  • –status=
    Only lists entries with a particular status. Accepts active and trash. Defaults to active.

  • –format=
    The format in which the entries should be output. Accepts table, csv, json, and count. Defaults to table.

  • –page-size=
    The number of entries to output. Defaults to 20.

  • offset=
    The number of entries to skip when outputting. Defaults to 0.

Updating Entries

Using JSON

Example

wp gf entry update 5 --entry-json='{"is_read":1}'

Parameters

  • entry-id
    The ID of the entry to be updated.

  • –entry-json=
    JSON containing the full JSON of the entry.
    Note: any values not defined will be replaced with null values.

Using Field/Value arguments

Example

wp gf entry update 5 --field_1="My Value" --field_2="Another value"

Parameters

  • entry-id
    The ID of the entry to be updated.

  • –field=value
    The field/value pairs to be updated. For example, –field_1=”My Value”