Home › Forums › Front-end Issues › How to remove search box for Taxonomy field?
Hello,
I have Taxonomy field displayed as Select.
I would like to remove search dropdown in the field.
Stylized UI option is missing in settings in admin (It’s present in regular Select field though).
I believe I can do so using JavaScript API but can’t figure out how-to
acf.add_filter('select2_args', function(args, element, settings) {
//Something here
}
return args;
});
I think this is late for reply but these is a trick… u can use js or css to do like this:
$('.select2-search').css({
"display":"none"
});
Hi sabrinazeiden,
You’re absolutely right about using the select2_args filter – that’s the correct approach since Taxonomy fields use Select2 but don’t expose the “Stylized UI” option. Here’s the JavaScript that will remove the search box:
javascript
acf.add_filter(‘select2_args’, function(args, $select, settings) {
// Check if this is a taxonomy field
if (settings.field_type === ‘taxonomy’) {
// Remove the search functionality
args.minimumResultsForSearch = -1;
}
return args;
});
Alternative approach – if you want to target specific taxonomy fields by their key or name:
javascript
acf.add_filter(‘select2_args’, function(args, $select, settings) {
// Target by field key
if (settings.field_key === ‘field_1234567890abc’) {
args.minimumResultsForSearch = -1;
}
// OR target by field name
if (settings.field_name === ‘your_taxonomy_field_name’) {
args.minimumResultsForSearch = -1;
}
return args;
});
Where to add this code:
In your theme’s JavaScript file that loads in admin
Or in the ACF admin footer using this PHP:
php
add_action(‘acf/input/admin_footer’, function() {
?>
<script>
acf.add_filter(‘select2_args’, function(args, $select, settings) {
if (settings.field_type === ‘taxonomy’) {
args.minimumResultsForSearch = -1;
}
return args;
});
</script>
<?php
});
The minimumResultsForSearch = -1 trick tells Select2 to never show the search box, regardless of how many options there are. This is much cleaner than trying to hide it with CSS.
This should completely remove the search dropdown from your Taxonomy select fields while keeping the regular Select fields unaffected.
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.