Inheritance filters in view I've got content-type with two fields with real values. Their interior name are field_price1 and field_price2. I created page view includes contents. I've got search. I want to allow user to give some value(s) in search (min and max) to seek contents. I want to display only these contents whose field_price1 OR field_price2 is between min and max filled in by user. 

Has someone any ideas?

I tried and I decided to create two filters. First filter (for field_price1) exposed, second (for field_price2) not. So that, in my search I've got two inputs (I chose between operator). I wanted the second filter inherits values from first filter. I coded:


function customSearch_views_pre_execute(&$view) {  
  if ($view->name == 'search') {        
    $filters = $view->display_handler->get_option('filters');   
    $filters['field_price2_value']['value']['min'] = $view->exposed_input['field_price1_value']['min'];
    $filters['field_price2_value']['value']['max'] = $view->exposed_input['field_price1_value']['max'];
    $view->display_handler->override_option('filters', $filters);
  }
}


I place that function in my custom module named customSearch. My view is named search. Unfornately it doesn't work. Second filter doesn't inherit values from first one. I don't know why. Could someone help me, please?
You will need to implement hook_views_query_alter to get this going.

Start with the filters in Views.



Make your filters look exactly like this. With that I mean that there should be two groups of filters with AND between the groups. And you need to set Or in the second group. This is important otherwise the code below will not work.

Then replace hook_views_pre_execute with the code below for hook_views_query_alter. I also recommend you rename your module to customsearch instead of customSearch, small letters is standard in function names for Drupal.

/**
* Implements hook_views_query_alter().
*/
function customsearch_views_query_alter(&amp;$view, &amp;$query) {
  if ($view-&gt;name == 'search') {
    if (isset($query-&gt;where[2]['conditions'][0]['field']) &amp;&amp; $query-&gt;where[2]['conditions'][0]['field'] == 'field_data_field_price1.field_price1_value') {      
      $query-&gt;where[2]['conditions'][1]['value'][0] = $query-&gt;where[2]['conditions'][0]['value'][0];
      $query-&gt;where[2]['conditions'][1]['value'][1] = $query-&gt;where[2]['conditions'][0]['value'][1];
    }
    else {
      unset($query-&gt;where[2]);
    }
  }
}


In the code I first check to see if something has been entered in the exposed filter. If it is present we populate the second filter's values.

If you enable the module devel and do dsm($query) just before the last } you can debug and look in  the array yourself. For exammple number 2 in $query->where[2] means the second group of filters, which you will see easily if you debug.

Update: I've added an else statement so that the price fields are not in effect at all if nothings been entered in the in betweens.