hook_views_query_alter all condition I have an exposed filter that shows products which have multiple entity references. The user should be able to pick some number of entities and the view should show entities containing all those references. In my mind that should mean changing the in operator on the where clause to an all operator. 

function hook_views_query_alter(&amp;$view, &amp;$query) {
  if ($view-&gt;vid == 7) {
    dpm ($query);
    if (isset($query-&gt;where[1]['conditions'][2]['operator'])) {
      $query-&gt;where[1]['conditions'][2]['operator'] = 'all';
    }
    dpm ($query);
  }
}


However this seems to have no effect. the operator is changed from the first dpm to the second and it does break if I enter some other value in the all does not change the results. Do I have the wrong operator? Or am I going about this all wrong?

[edit]
According to Payou the function should look like 

function falk_products_query_products_alter($query) {
  $conditions = &amp;$query-&gt;conditions();
  $conditions2 = &amp;$conditions[0]['field']-&gt;conditions();
  $conditions3 = &amp;$conditions2[0]['field']-&gt;conditions();
  $my_query = &amp;$conditions2[0]['field'];
  $my_conditions = &amp;$my_query-&gt;conditions();
  dpm ($my_query-&gt;conditions());

  if (isset($my_conditions[2])) {
    foreach ($my_conditions[2]['value'] as $target) {
      $my_query-&gt;condition($my_conditions[2]['field'], array($target), 'in');
    }
  }
  dpm ($my_query-&gt;conditions());
}


Which at the dpm's give me arrays that look good to me but dont work if more than one value is input.
Altering a query like this is really not recommended.

First of all, you should use SelectQuery methods provided by "$query" variable.
You can get an array of query conditions by using "SelectQuery::conditions()" method.

Be careful, if you want to alter this array get the array like the following snippet :

$conditions =&amp; $query-&gt;conditions();
//Now you can use and alter your query conditions.


Some others tips related to your code :

1) You can tag your query in Views UI

Add a tag to your Views Query :


With this trick you can define a special hook for altering all query who use this tag. This hook is "hook_query_TAG_alter"

Now you can use this code :

function YOUR_MODULE_query_my_tag_alter($query) {
  $conditions =&amp; $query-&gt;conditions();
  //This condition is useless now
  //if ($view-&gt;vid == 7) {
  //Check conditions and do your updates

  //}
}


2) Careful to the module weight

When you alter something, other modules can do it too...
This order is determined by the module weight saved in the "system" table.

By using your own tags on your query, other modules should not know about this tag and should not alter your query.

You can change your module weight but this is not the thread of this post

Links

SelectQuery Api

SelectQuery::conditions() method

Query Alteration recommandations by Drupal

hook_query_TAG_alter

Change Module Weight