Skip to content

Instantly share code, notes, and snippets.

@GoZOo
Created June 4, 2013 08:15
Show Gist options
  • Select an option

  • Save GoZOo/5704400 to your computer and use it in GitHub Desktop.

Select an option

Save GoZOo/5704400 to your computer and use it in GitHub Desktop.
Drupal code: Exclude some content types from node search
<?php
/**
* Implements of hook_query_node_access_alter().
* Exclude some content types from node search
* Ne pas prendre en compte certains types de contenu dans la recherche
*/
function mymodule_query_node_access_alter(QueryAlterableInterface $query) {
global $user;
// No exclude for super admin
if ($user->uid == 1) {
return;
}
$search = FALSE;
$node = FALSE;
foreach ($query->getTables() as $alias => $table) {
if ($table['table'] == 'search_index') {
$search = $alias;
}
elseif ($table['table'] == 'node') {
$node = $alias;
}
}
if ($node && $search) {
$excluded_content_types = array('contenttype1', 'contenttype2', 'contenttype3');
// A core bug results in a DB error if we use the following: Ref: #1210072
$query->condition($node . '.type', array($excluded_content_types), 'NOT IN');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment