Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zackkatz/2b87d492ee08aaf7dfaa5567308bc9b8 to your computer and use it in GitHub Desktop.
Save zackkatz/2b87d492ee08aaf7dfaa5567308bc9b8 to your computer and use it in GitHub Desktop.
Override search field values in GravityView
<?php
/**
* This is as shown in the video here: https://www.loom.com/share/68f01c9661264f30bb43e9f5346c7b83
*/
/**
* @param \GravityView_Widget_Search $search_obj GravityView Widget instance
*/
add_action( 'gravityview_search_widget_fields_before', function( $search_obj ) {
// Only override search field values when a URL parameter is passed.
// If you always want to override, delete the following line.
if ( ! isset( $_GET['example'] ) ) { return; }
foreach( $search_obj->search_fields as $key => &$search_field ) {
switch( $search_field['key'] ) {
case 'search_all':
$search_field['value'] = 'Search all override';
break;
case '1':
$search_field['value'] = 'Duration override';
break;
}
}
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment