Managing Fields with WP-CLI

Managing Fields with WP-CLI

Creating FieldsExamplesParametersDeleting FieldsExamplesParametersDuplicating FieldsExamplesParametersEditing FieldsExamplesParametersGetting FieldsExamplesParametersListing FieldsExamplesParametersUpdating FieldsExamplesParameters

When using the CLI Add-On for Gravity Forms, you are able to easily manage your forms fields using only the command line, via WP-CLI. In this article, we will show you how to do things such as update, delete, and even create form fields using WP-CLI.
Creating Fields
wp gf field create
Examples

Create a new text type field for form 1.
wp gf field create 1 text 'My Text Field'

Create a new select field for form 1 from the supplied JSON.
wp gf field create 2 --field-json='{"type": "select", "label": "My Dropdown", "enableChoiceValue": true, "choices": [{"text": "Choice 1", "value":"one"}, {"text": "Choice 2", "value":"two"}]}'

Parameters

Argument
Description

The ID of the form to create a field in.


The type of field to create.Examples: text, textarea, email.See the type properties of the field classes which extend GF_Field.

[

[--field-json=]
The JSON formatted field properties.

[--porcelain]
Outputs just the created field ID.

Deleting Fields
wp gf field delete
Examples

Deletes field 2 from form 5.
wp gf field delete 5 2

Parameters

Argument
Description

The ID of the form that a field will be deleted from.


The ID of the field to be deleted.

Duplicating Fields
wp gf field duplicate
Examples

Duplicates field 2 of form 5.
wp gf field duplicate 5 2

Parameters

Argument
Description

The ID of the form that a field will be duplicated in.


The ID of the field to be duplicated.

Editing Fields
wp gf field edit
Examples

Launch the editor for field 2 of form 5.
wp gf field edit 5 2

Parameters

Argument
Description

The ID of the form that contains the field you want to edit.


The ID of the field to be edited.

Getting Fields
wp gf field get
Examples

Gets the JSON for field 2 of form 5.
wp gf field get 5 2

Parameters

Argument
Description

The ID of the form that contains the field you want to view.


The ID of the field you want to view.

Listing Fields
wp gf field list
Examples

Get a table formatted list of fields from form 5.
wp gf field list 5

Parameters

Argument
Description

The ID of the form that you want to list fields from.

[--format=]
Defines the format in which the fields will be listed.Accepted values: table, csv, json, yaml, and count.Default: table.

Updating Fields
wp gf field update
Examples

Updates field 2 of form 5 with the supplied JSON.
wp gf field update 5 2 --field-json='{"type": "text", "label": "My New Label", "defaultValue": "Just testing"}'

Update the specified properties of form 2 field 5.
wp gf field update 5 2 --type=text --label='My New Label'

Parameters

Argument
Description

The ID of the form that contains the field that will be updated.


The ID of the field you want to update.

[--=]
The field property and value to be updated.

[--field-json=]
The JSON formatted field properties.

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注