How to stop the Go Back link from clearing the search
On a Single Entry page, the Go Back link leads back to the Multiple Entries page and drops the visitor’s search. They land on the full list and have to search again. The snippet in this guide keeps the search on the way to the entry and on the way back, and one more line keeps it when users edit an entry.

Default behavior without the snippet #
The search is dropped twice. The link to a single entry leaves out the Search Bar’s values, and the Go Back link adds back only the page number and the sort order.
GravityView keeps a list of reserved query parameters off the links it builds, and the Search Bar adds its own parameters to that list.

With Connected Views in GravityView Pro, the Back link from an entry to a connected list keeps the search made on that list. A visitor who searches a client’s projects, opens one and clicks “Back to Projects” returns to the same results without the snippet. The first list, where visitors start, works like any other View, so it needs the snippet to keep its search.
Adding the snippet #
Add this code to your site:
/**
* Adds the Search Bar's values from the current address to a link
* that GravityView builds.
*
* @param string $url The link.
*
* @return string The link with the search added.
*/
$gv_carry_search = static function ( $url ) {
$keys = [
'mode', 'gv_search', 'gv_start', 'gv_end',
'gv_id', 'gv_by', 'gv_search_view',
];
// WordPress adds a backslash before each quote in $_GET,
// and wp_unslash() takes it out again.
$search = array_filter( wp_unslash( (array) $_GET ), static function ( $key ) use ( $keys ) {
return 0 === strpos( (string) $key, 'filter_' )
|| in_array( $key, $keys, true );
}, ARRAY_FILTER_USE_KEY );
// add_query_arg() adds new values without encoding them, so encode
// them first to keep characters such as &, # and + in the search.
return $search ? add_query_arg( urlencode_deep( $search ), $url ) : $url;
};
add_filter( 'gravityview/entry/permalink', $gv_carry_search, 10 );
add_filter( 'gravityview/template/links/back/url', $gv_carry_search, 10 );Note: To add a snippet to your site, see Adding custom PHP code snippets to your website.
Then search the View, open an entry and click Go back. The list comes back with the same results, and the Search Bar still shows the search.

Replace any older copy of this snippet that has no urlencode_deep(). An older copy brings back the wrong entries, or none, after Go back and Update when the search holds a quotation mark, &, # or +, and after Update when it holds an apostrophe.
The entry link filter and the Go Back filter #
The gravityview/entry/permalink filter adds the search to the link that opens a single entry. Without it, the search is gone by the time the visitor reaches the entry.
The gravityview/template/links/back/url filter puts the same values on the Go Back link. Both copy the same short list: the Search Bar’s filter_ fields, mode, and the gv_ search keys. Everything else in the address is left alone.
Before the values go on a link, the snippet takes out the backslashes WordPress puts before quotation marks and apostrophes, and encodes each value. A search for Forlì nell'Emilia or Boston & Cambridge then reaches the next page as the visitor typed it.
Note: The snippet needs both filters. With only the first one, the entry’s address has the search, and the Go Back link still drops it.
Keeping the search after editing an entry #
The snippet doesn’t reach Edit Entry. The Edit link and the Redirect to Multiple Entries setting start from the View’s own address, so a user who edits an entry and clicks Update comes back to every entry. When Edit Entry opens in a lightbox, the page reloads with the search instead.
To keep the search after Update, add this line after the snippet’s two add_filter lines:
add_filter( 'gravityview/view/links/directory', $gv_carry_search, 10 );Note: Adding custom PHP code snippets to your website explains where to add this code.
Choosing where users go after editing an entry shows the whole code and what else the line changes: Delete and Duplicate keep the search too.
Copying only the search parameters #
The snippet copies only the search parameters it names. Copying the whole address would also copy the reserved parameters that GravityView and add-ons such as DataTables keep off their links.
Some older copies of this snippet take the Search Bar’s parameters off the reserved list. The Search Bar then sends each field twice, and the old value wins, so a new search shows the previous results. Replace those with the code above too.