Here's how to do it avoiding above pitfalls (put in custom.module):
/**
* Implementation of hook_views_query_alter().
*/
function custom_views_query_alter(&$view, &$query) {
if ($view->name == 'My_View' && $view->current_display == 'page') {
// Don't display results until at least one exposed filter has a value set.
$filter_set = FALSE;
foreach ($view->filter as $filter) {
// Check if we've found a filter identifier that is set.
if ($filter->options['exposed'] && array_key_exists($filter->options['expose']['identifier'], $_GET)) {
$filter_set = TRUE;
break;
}
}
// If the filter isn't set, add a WHERE clause to the query that
// cannot be TRUE. This ensures the view returns no results.
if (!$filter_set) {
$query->add_where(0, 'FALSE');
// To display a different message (or no message at all) you
// also might want to adjust the Views' empty text.
//$view->display_handler->options['empty'] = '';
}
}
}

