in the search box I would like visitors to be able to search for more than one location (houses). The code right now is:

    <div class="col-md-3 col-sm-6 col-xs-12">
        <label for="property_location"><?php _ex( 'Locatie', 'property search label', 'ci_theme' ); ?></label>

        <div class="ci-select">
            <?php
                wp_dropdown_categories( array(
                    'taxonomy'          => 'property_location',
                    'hierarchical'      => true,
                    'show_option_none'  => esc_html_x( '-', 'any property location', 'ci_theme' ),
                    'option_none_value' => '',
                    'name'              => 's_property_location',
                    'id'                => 'property_location',
                    'selected'          => isset( $_GET['s_property_location'] ) ? $_GET['s_property_location'] : '',
                ) );
            ?>
        </div>
    </div>

How do I change this to a multiple select?

Thank you so much for your answer.
Carlijn

4 Answers
4

wp_dropdown_categories has a filter applied to the output that is called right before the function returns or echos the output.

With this you can add a filter to your funtions.php file that manipulates the select field and adds a multiple attribute to it.

The filter below would search for the select opening tag and add the multiple attribute to it. You can also add the size attribute to control the number of items displayed at a time.

add_filter( 'wp_dropdown_cats', 'dropdown_filter', 10, 2);

function dropdown_filter( $output, $r ) {
    $output = preg_replace( '/<select (.*?) >/', '<select $1 size="5" multiple>', $output);
    return $output;
}

Tags:

Leave a Reply

Your email address will not be published. Required fields are marked *