(Advanced) Only show choices in the Search Bar that exist in entries

If you have a Country field in your form and you only have entries representing five countries, you may want to only show those five countries in a front-end Search Bar instead of hundreds of countries.

To limit searchable drop-down fields to only values that have been submitted, add this filter:

add_filter( 'gravityview/search/sieve_choices', '__return_true' );

If you want to limit this behavior to specific Views and specific form fields, modify this code:

// Only show used choices in entries for View ID 4 and Field ID 6
add_filter( 'gravityview/search/sieve_choices', function( $sieve, $filter, $context ) {
    if ( 4 === $context->view->ID && 6 === (int) $filter['key'] ) {
        return true;
    }
    return $sieve;
}, 10, 3 );

Note: This will match both the choice label and the choice value.

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