If you wish to enable Select2 in your BP Profile Search forms, add this code to your bp-custom.php:
add_action ('bps_before_search_form', 'bps_enable_select2');
add_action ('bp_ps_before_search_form', 'bps_enable_select2');
function bps_enable_select2 ($F)
{
wp_enqueue_script ('select2-js', 'https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.13/js/select2.min.js', array ('jquery'));
wp_enqueue_style ('select2-css', 'https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.13/css/select2.min.css');
?>
<script>
jQuery(function ($) {
$('.bps-selectbox select').select2({width: '10em', dropdownAutoWidth: true});
$('.bps-multiselectbox select').select2({width: '10em', dropdownAutoWidth: true});
});
</script>
<?php
}
Please note that there are two calls to select2(), one to enable Select2 for standard drop-down fields (line 10), and the other to enable it for multi-select fields (line 11). If you aren’t interested in both, simply delete the line you don’t need.
The JavaScript object inside a select2() call contains your Select2 configuration options, and you can change them according to your needs. You can find the list of all the Select2 configuration options in:
