Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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