By default Drupal Exposed Filters query string includes all filters even if they aren't selected i.e. www.example.com/?optiona=valuea&optionb=all&optionc=all

How do I adjust it not include default/all values in the query string?

For example, if the user does not touch "option b" just option a they would get

i.e. www.example.com/?optiona=valuea

The goal is to create a "cleaner" query string by not including the default values.


This is a known issue that hopefully will be solved in Drupal 8.

I accomplished it with JS:

jQuery(document).ajaxComplete(function(e, xhr, settings) {

let src = window.location.href;
let url = new URL(src);
let title= document.title;
let re = /all/;
let props = [...new URLSearchParams(url.search)]
            .filter(([key, prop]) => !re.test(prop));
url = url.origin + url.pathname;
let params = new URLSearchParams();
props.forEach(([key, prop]) => params.set(key, prop));
url += "?" + params.toString();

history.pushState(null, null, ("/page?"+params.toString()))


You can use Views expost module which allows you to set the exposed filters forms in views to use method POST instead of GET.

Now when you submit the filters the form will be submitted to drupal using POST method which means any selections won't appear in the url.

You can have full control over the markup of these filters

views-exposed-form--view_id--display_id.tpl.php views-exposed-form.tpl.php

Or attach JS code to achieve what you need

function yourtheme_form_alter(&$form, $form_state, $form_id) {
 switch ($form_id)  {
   case 'views_exposed_form':
     if($form['#id'] == 'views-exposed-form-viewid-displayid'){
         $form['#attached']['js'] = array(drupal_get_path('module', 'ajax_example') . '/ajax_example.js',


  • Thanks @Mohammed but Views expost will remove the entire query string. I want to keep the query string for active filters, I only want to hide the default "any" values since they are unnecessary and clutter up the URL. – Sam Oct 14 '17 at 9:10
  • Try JS solution on forn submit check filter values and build the query. – Mohammed Gomma Oct 14 '17 at 10:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.