Support

Account

Home Forums Front-end Issues How to remove search box for Taxonomy field?

Solving

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.

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.