0

In drupal 7, How do I alter the existing filter? For example, I have a node title as an exposed filter and in hook_search_api_query_alter I want if any node title starts with "c" character brings all the nodes starts with "C" characters.

Below is my code which is adding a new condition, however, I want to update the existing filter condition.

function product_glossary_search_api_query_alter(SearchApiQueryInterface $query) {
  if (arg(0) == 'product-search') { 
    if (isset($_REQUEST['title'])) {
      if (!empty($_REQUEST['title']) && strlen($_REQUEST['title']) == 1) {  
        $char_search = $_REQUEST['title'];
        $query->condition('title', $char_search.'%', 'LIKE');
      }
    } 
  }
}

Output of this alter is as below. enter image description here

Please suggest.

Your Answer

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

Browse other questions tagged or ask your own question.