How to implement hook_views_query_alter? I used this topic before asking question but even if the problem is very very closed, the answers given did not work for me.

So I need to alter the query of one of my views in drupal 7. I created a new module called for example 'mymodule'. This module contains


.info file.
.module file.
.views.inc file.


My .module file contains the following. Note that my .views.inc file is located at the root of the module directory. I also checked that my views api version is 3 :

function modulename_views_api() {
  return array(
    'api' =&gt; 3,
    'path' =&gt; drupal_get_path('module', 'modulename'),
  );
}


My .views.inc file, which is at the root of the module directory contains the following :

function modulename_views_query_alter(&amp;$view, &amp;$query) {
dpm($view);
watchdog('error title', 'error message');
echo 'TEST TEST';
die('test');
if ($view-&gt;name == 'my_view_name' &amp;&amp; $view-&gt;current_display == 'my_display_name') {
    unset($query-&gt;where[1]['conditions'][0]);
    unset($query-&gt;where[1]['conditions'][1]);
 }
}


I can't see what I am missing trying to implement this hook but it never go into the views_query_alter function (I cleared the cache before trying). I think I've followed all advices given in the link provided above.

Any help would be appreciated.
.views.inc file is to separate the views alter logic.

hook_views_api to add the mymodule.views.inc file which can be with path your-module/includes/views or at the root of your module.

You also can use mymodule_views_query_alter at mymodule.module file which should work fine.

Please remove the cache after applying the changes.