Monday, December 16, 2013

Custom search box for a specific content type

Make a custom search box on my site that would only search a single content type, with results identical to if the user had done an advanced search and selected one content type only. The code below works perfectly for me. Replace "your_content_type" with the content type to which you'd like to restrict the search.


<form action="/search/node" method="post" id="search-form" class="search-form">
<div class="form-item">
<input type="text" class="input-text" value="" size="25" name="keys" />
<input type="submit" value="Search" name="op" title="Search" alt="Search" />
<input type="hidden" value="<?php print drupal_get_token('search_form'); ?>" name="form_token" />
<input type="hidden" value="search_form" id="edit-search-form" name="form_id" />
<input type="hidden" name="type[your_content_type]" id="edit-type-your_content_type" value="your_content_type" />
</div>
</form>

No comments:

Post a Comment