Search: Changing the default option in a select (drop down) field

By default, the first option of a drop-down field (also called a "select") on a search bar is a dash "—". 

Dropdown for selecting business type with search button below

We can change that to a more intuitive text like "-- Select --" by using this code below:

/**
 * Modify the text for the default option in a select (multi or single dropdown)
 *
 * @param string $default_option Default: `—` (—)
 * @param string $field_type Field type: "select" or "multiselect"
 * 
 * @return string
 */
add_filter( 'gravityview/extension/search/select_default', function( $default, $select_type = 'select' ) {

	if( 'select' === $select_type ) {
		return '-- Select --';
	}
	
	return '-- Select One or More --';
}, 10, 2 );

Read here how to add these code samples to your website: Where to put code samples.

Here's how it'll look now:

Dropdown labeled 'Business Type' with default '-- Select --' and red 'SEARCH' button

The same code snippet works for Multi Select fields:

Dropdown for selecting industries: Air Transportation, Apparel Manufacturing, Crop Production, with default "Select One or…

Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.

Still need help? Contact Us Contact Us