function hook_query_alter
Perform alterations to a structured query.
Structured (aka dynamic) queries that have tags associated may be altered by any module before the query is executed.
Parameters
$query: A Query object describing the composite parts of a SQL query.
See also
node_query_node_access_alter()
Related topics
8 functions implement hook_query_alter()
Note: the procedural functions in this list are found by pattern matching, so the list may include some functions that are not actually implementations of this hook.
- DatabaseTestHooks::queryAlter in core/
modules/ system/ tests/ modules/ database_test/ src/ Hook/ DatabaseTestHooks.php  - Implements hook_query_alter().
 - database_test_query_alter in modules/
simpletest/ tests/ database_test.module  - Implements hook_query_alter().
 - field_test_entity_query_alter in modules/
field/ tests/ field_test.module  - Implements hook_entity_query_alter().
 - field_test_query_store_global_test_query_alter in modules/
field/ tests/ field_test.module  - Implements hook_query_TAG_alter() for tag 'store_global_test_query'.
 - search_node_tags_query_alter in modules/
search/ tests/ search_node_tags.module  - Implements hook_query_alter().
 
File
- 
              modules/
system/ system.api.php, line 3318  
Code
function hook_query_alter(QueryAlterableInterface $query) {
  if ($query->hasTag('micro_limit')) {
    $query->range(0, 2);
  }
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.