0

Is it possible to have custom search pages that filter based on content type? I attempted adding a hidden input to the search form like so:

<form class="search-block-form" data-drupal-selector="search-block-form-7" action="/search/node" method="get" id="search-block-form--7" accept-charset="UTF-8" data-drupal-form-fields="edit-keys--7">

<input title="Enter the terms you wish to search for." data-drupal-selector="edit-keys" type="search" id="edit-keys--7" name="keys" value="" size="15" maxlength="128" class="form-search">

<input data-drupal-selector="edit-submit" type="submit" id="edit-submit--8" value="Search" class="button js-form-submit form-submit">

<input type="hidden" name="type" value="blogpost">

</form>

But the search results page ignores the 'type' variable in the GET request and displays all results instead of just the results of the content type I want. I also noticed that you can create multiple custom search pages in the configuration page, but there doesn't seem to be any options for filtering by content type. Is there anyway to have a search page that filters based on content type? Preferably without creating a view page.

1

A few things to note:

  1. The Advanced Search portion of Drupal core search (that filters by type) works by POSTing to the /search/node route so altering the form wouldn't help here.
  2. For custom search pages, the Advanced Search > Content types option is for controlling the display only so it won't help here.

The core search block doesn't have the ability to customize for filtering on types, but a contrib module called Custom Search will. Under its Content configuration section there exist options to control what can be selected as content types to filter on.

  • Would the Custom Search module allow multiple custom search pages each with their own filters? – Matt Nov 8 '16 at 14:41
  • Yes, under the Content configuration section there is a Search Page option that allows you to target a specific search page. With D8's entity blocks, you can create multiple copies of block each with a different configuration. – Shawn Conn Nov 8 '16 at 16:29
1

You can use "custom search" module for filter search by a particular content type

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.