7.x search.api.php hook_search_info()

Define a custom search type.

This hook allows a module to tell search.module that it wishes to perform searches on content it defines (custom node types, users, or comments for example) when a site search is performed.

In order for the search to do anything, your module must also implement hook_search_execute(), which is called when someone requests a search on your module's type of content. If you want to have your content indexed in the standard search index, your module should also implement hook_update_index(). If your search type has settings, you can implement hook_search_admin() to add them to the search settings page. You can use hook_form_FORM_ID_alter(), with FORM_ID set to 'search_form', to add fields to the search form (see node_form_search_form_alter() for an example). You can use hook_search_access() to limit access to searching, and hook_search_page() to override how search results are displayed.

Return value

Array with optional keys:

  • title: Title for the tab on the search page for this module. Title must be untranslated. Outside of this return array, pass the title through the t() function to register it as a translatable string.
  • path: Path component after 'search/' for searching with this module. Defaults to the module name if not given.
  • conditions_callback: An implementation of callback_search_conditions().

Related topics

3 functions implement hook_search_info()

Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.

node_search_info in modules/node/node.module
Implements hook_search_info().
search_extra_type_search_info in modules/search/tests/search_extra_type.module
Implements hook_search_info().
user_search_info in modules/user/user.module
Implements hook_search_info().


modules/search/search.api.php, line 42
Hooks provided by the Search module.


function hook_search_info() {

  // Make the title translatable.
  return array(
    'title' => 'Content',
    'path' => 'node',
    'conditions_callback' => 'callback_search_conditions',


ablondeau’s picture

If you have implemented this hook and the tab is not showing up, go to admin/config/search/settings and make sure the checkbox for your module is checked.

narasimharaosp’s picture

Thanks ablondeau. I went through code but its little tricky to find config, if the modules are customizied.

therainmakor’s picture

The FORM_ID in the following sentence should be replaced with 'search_form'.

You can use hook_form_FORM_ID_alter(), with FORM_ID set to 'search', to add fields to the search form (see node_form_search_form_alter() for an example).

asukhdhan’s picture

How can we set the priority for search tabs to be shown. i have 1 from the website search and 2 other search tabs created from hook_search_info() . I want the tabs to show up like website search followed by the custom search tabs created.

coredumperror’s picture

The only way I've found to do this is to implement my_theme_menu_local_tasks(), change the order of the $variables['primary'] array to the way I want my search tabs to appear, then call return theme_menu_local_tasks($variables) to let Drupal's core menu system actually render the local tasks.

There is a "weight" value in each task's #link array, but changing it in the theme layer doesn't work. You have to re-sort the array to change the rendering sequence. Perhaps there a way to hook into the process at an earlier level to change the weights in a meaningful way, but I haven't found it.

shenzhuxi’s picture

Seems I can't create more than one tab on search page in one module.
This hook should allow multi-search entries in one module, like:

function hook_search_info() {
  return array(
      'title' => 'Content', 
      'path' => 'node', 
      'conditions_callback' => 'sample_search_conditions_callback_1',
      'title' => 'File', 
      'path' => 'file', 
      'conditions_callback' => 'sample_search_conditions_callback_2',
web_junkie’s picture

Yeah, I was just thinking the same thing. I ended up making 4 different modules for this, but it would really be nice to combine them. You should be able to return an array of search_info hooks in the same way that hook_menu does it...

almc’s picture

Seems that in D7 when you use this hook for custom modules, their paths add to the 'root' /search path, forming multiple tabs on one page for each module's search. What would be a clean way to show only selected search tabs, depending on the context (e.g. current path in the browser address bar)?

d8v15’s picture

Is it not possible to have those hooks include the external table/database in the normal search results. I dont want a separate tab. I would just want a list of normal search results that includes results from the external table without requiring an additional plugin. Please give small example.