In Drupal 7 hiding content type from search results in your application is pretty simple. Hook node access alter will provide the interface to bypass the search result query.
hook_query_node_access_alter()
Hide content-type
For example if there is a content type called “some_type” in your application, which you don’t want to show in your search result when you search for nodes in Drupal 7. To hide “some_type” content type you can write a hook in your custom module as below,
/** * Implements of hook_query_node_access_alter(). */ function <MODULE_NAME>_query_node_access_alter(QueryAlterableInterface $query) { $excluded_content_types[] = "some_type"; if (!empty($excluded_content_types)) { $db_and = db_and(); foreach ($excluded_content_types as $type) { $db_and->condition($node . '.type', $type, '!='); } $query->condition($db_and); } } }
If you enable your custom module from admin/drush then the search result from your Drupal application will hide “some_type” from your search result.
If you are a Drupal developer following the above trick will help you to hide the content-type, if you are not a drupal developer you can get configurable module from your admin end and you can configure which content type to hide from search results
The post Drupal 7 hide content type from search results appeared first on Mydons.