Limit filter operators

Drupal Answers Asked on November 5, 2021

Is there a way to limit the operators for views-filtering for users. I want them to only have “starts-with”, “contains” and “same”. But not the rest. Do I have to form_alter with a custom module? Or is there some intern way to achieve that?

One Answer

I don't think there is an option to sort the exposed operators.

You can do it with a custom module using hook_form_alter().


function module_name_form_alter(&$form, &$form_state, $form_id) {

  if ($form_id == 'views_exposed_form' && $form_state['view']->name == 'view_name') {
    unset($form['field_name_filter_op']['#options']['not empty']);


You can find the form details using "dpm()" from devel module.

  • dpm($form_id);
  • dpm($form);
  • dpm($form_state);

Answered by NeoHQ on November 5, 2021

Add your own answers!

Related Questions

Make node only accesible by path alias

3  Asked on November 19, 2021 by kevin-ramirez-zavalza


Form and gated content

1  Asked on November 17, 2021 by dataguy


Calculate Star rating based on webform submissions

1  Asked on November 17, 2021 by brainhax


Pager not working when $form[‘table’] is called with AJAX

1  Asked on November 17, 2021 by user3428971


Send message notification when license expired

1  Asked on November 15, 2021 by learner123


View filtering, Relationship Vs Contextual filter

1  Asked on November 15, 2021 by bassem-mohamed


Missing some block fields

1  Asked on November 15, 2021 by metalbearsolid


Custom template for each profile2 profile type edit form

1  Asked on November 13, 2021 by stavovei-ciprian


How to save an image resource

1  Asked on November 13, 2021 by kosher


How to alter node body content through Views pre render hook?

1  Asked on November 11, 2021 by pramodg


Set Default Value for Image Field contain Multiple Images

1  Asked on November 11, 2021 by pglatz


Ask a Question

Get help from others!

© 2023 All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP