Description
The “gform_filter_links_entry_list” filter in Gravity Forms allows the list of filters at the top of the Entry List page to be modified.
Usage
add_filter( 'gform_filter_links_entry_list', 'your_function_name', 10, 3 );
Parameters
Parameter | Type | Description |
---|---|---|
$filter_links | array | The filter links. |
$form | array | The form the filter links are being prepared for. |
$include_counts | bool | Indicates if the database query to get the counts was performed. |
$counts | array | The number of entries that match the filters when $include_counts is true. |
Filter Links
array (
0 =>
array (
'id' => 'all',
'field_filters' =>
array (
),
'count' => '',
'label' => 'All',
),
1 =>
array (
'id' => 'unread',
'field_filters' =>
array (
0 =>
array (
'key' => 'is_read',
'value' => false,
),
),
'count' => '',
'label' => 'Unread',
),
2 =>
array (
'id' => 'star',
'field_filters' =>
array (
0 =>
array (
'key' => 'is_starred',
'value' => true,
),
),
'count' => '',
'label' => 'Starred',
),
3 =>
array (
'id' => 'spam',
'field_filters' =>
array (
),
'count' => '',
'label' => 'Spam',
),
4 =>
array (
'id' => 'trash',
'field_filters' =>
array (
),
'count' => '',
'label' => 'Trash',
),
)
Examples
Basic usage.
This example will simply add the ‘My Custom Link’ to the Entries list page. It will not filter anything because it has a blank array for ‘field_filters’. So you would need to provide your own filter to make it work.
add_filter( 'gform_filter_links_entry_list', 'change_links', 10, 4 );
function change_links( $filter_links, $form, $include_counts, $counts ){
$filter_links[] = array(
'id' => 'mycustom',
'field_filters' => array(), // You need to provide a filter array here to make this link do something.
'label' => 'My Custom Link',
);
return $filter_links;
}
Filter entries by field value.
The following example will add a new ‘Value test for Field id 1’ link that will reduce the entries list to only entries where field ID 1 has test as value.
// Filter Entries List to show only entries with value 'test' for field id 1.
add_filter( 'gform_filter_links_entry_list', 'filter_list_by_field_value', 10, 4 );
function filter_list_by_field_value( $filter_links, $form, $include_counts, $counts ){
$filter_links[] = array(
'id' => 'filterbyfield',
'field_filters' =>
array (
0 =>
array (
'key' => 1, // ID of the field to check.
'value' => 'test', // Only entries with this value for the above field id.
),
),
'label' => 'Value test for Field id 1',
);
return $filter_links;
}
Add a filter for “Not Starred” entries.
The following example will add a new ‘Not Starred’ link that will filter the entries list to show only entries where the is_starred property is set to false (entries with the gray star icon).
add_filter( 'gform_filter_links_entry_list', 'add_not_starred_filter', 10, 4 );
function add_not_starred_filter( $filter_links, $form, $include_counts, $counts ) {
$summary = $include_counts ? GFFormsModel::get_form_counts( $form['id'] ) : array();
$active_entry_count = absint( rgar( $summary, 'total' ) );
$starred_count = absint( rgar( $summary, 'starred' ) );
$filter_links[] = array(
'id' => 'no-star',
'field_filters' => array(
array( 'key' => 'is_starred', 'value' => false ),
),
'count' => $active_entry_count - $starred_count,
'label' => esc_html_x( 'Not Starred', 'Entry List', 'gravityforms' ),
);
return $filter_links;
}
Placement
This code can be used in the functions.php file of the active theme, a custom functions plugin, a custom add-on, or with a code snippets plugin.
See also the PHP section in this article: Where Do I Put This Code?
Since
This filter was added in Gravity Forms version 1.9.15 and in 2.9.16 the $counts parameter was added.
Source Code
This filter is located in GFEntryList::get_filter_links() in entry_list.php.