Skip to main content

PDF for GravityView Hooks – gfpdf_gv_cache_key_request_params

Description​

Return true from this filter when your custom Multiple Entries PDF template prints the visitor's search, such as a "Results for: plumber" heading or the selected date range.

A cached Multiple Entries PDF is matched to the entries it contains, not the search that found them (see Caching). Two searches that return the same entries get the same PDF. So if a visitor searches for "plumber" and then "electrician", the second PDF can still say "plumber".

When enabled, the request's search, sort and paging values (gv_search, gv_start, gv_end, gv_by, gv_id, sort, dir, pagenum, page_size and mode) become part of the cache key, and each combination is cached separately. Search field filters (filter_*) aren't included. The filter is off by default and only applies to Multiple Entries PDFs.

Only enable it for Views that need it, since every combination takes its own place in the cache. If your template prints a search field filter, turn off the cache for that View with gfpdf_gv_enable_pdf_cache instead.

See Template Overrides.

Version​

This hook was introduced in PDF for GravityView 2.0.

Arguments​

The following arguments are passed to functions that use this hook:

$include_params | bool​

  • Whether the request's search, sort and paging values are part of the cache key.
  • The default value is false.

$view | \GV\View​

  • The View the Multiple Entries PDF is being generated for.

Usage​

Your template override for View 885 starts with a heading built from the search:

<?php $search = sanitize_text_field( wp_unslash( $_GET['gv_search'] ?? '' ) ); ?>
<?php if ( $search !== '' ): ?>
<h2>Results for: <?php echo esc_html( $search ); ?></h2>
<?php endif; ?>

Cache a separate PDF for each search on that View:

add_filter( 'gfpdf_gv_cache_key_request_params', function( $include_params, $view ) {
if ( (int) $view->ID === 885 ) {
return true;
}

return $include_params;
}, 10, 2 );

Source Code​

This filter is located in src/Pdf/Caching/RequestParamsCacheKey.php of the PDF for GravityView extension.