Skip to content

Instantly share code, notes, and snippets.

@pierrenel
Created July 2, 2013 16:20
Show Gist options
  • Save pierrenel/5910768 to your computer and use it in GitHub Desktop.
Save pierrenel/5910768 to your computer and use it in GitHub Desktop.
Exclude a type of content from drupal search results, + limit to 8
/**
* Excludes node type "foo" from search results
*
* @param object $query
*/
function mymodule_query_alter(&$query) {
$is_search = FALSE;
foreach ($query->getTables() as $table) {
if ($table['table'] == 'search_index') {
$is_search = TRUE;
}
}
if ($is_search) {
$query->condition('n.type', 'foo', '<>')
->range(0,8);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment