How do I use hook_views_query_alter()? Following what reported in the documentation for hook_views_query_alter(), I created a file named alterform.views.inc and put it into an enabled module called alterform. I added  the following code in alterform.views.inc.but it doesn't work.

function alterform_views_query_alter(&amp;$view, &amp;$query) {
  switch($view-&gt;name) {
    case 'myViewName':  
      echo 'test test'; // test       
      $query-&gt;orderby[0] = "FIELD(node.type, 'story', 'page', 'productTypeC', 'productTypeD') ASC";
      $query-&gt;orderby[1] = "node_title ASC";
      break;
  }
}


why doesn't it output "test test"? What's wrong with my code?

there is still no output of test and views. what's wrong with my code? thank you
Right. In order to "do" anything with views in a module, you have to implement hook_views_api. Without this, your module won't be recognised by Views, at all, ever (AFAIK).

Please add the following to your module code:

/**
 * Implementation of hook_views_api().
 */
function alterform_views_api() { // your module name into hook_views_api
  return array(
    'api' =&gt; 2,
    // might not need the line below, but in any case, the last arg is the name of your module
    'path' =&gt; drupal_get_path('module', 'alterform'),
  );
}


This should fix it so your module is at least recognised, then you can start debugging it :)

A good way to start debugging a view (i.e. a baby step) is to put dpm($view); right at the start of the views function you're implementing. In most cases, that will dump info onto the screen that will help you see where you're at. Would suggest doing this with devel.module installed/switched on.

Edit: This assumes Views 2 and Drupal 6. You'd best ask around if those aren't your weapons of choice.