I did try to add a condition using hook_views_pre_execute or hook_views_query_alter, but since Im usiong SearchAPI, theres is no point apparently in using these functions (no $query in views_query_alter, and no query too in views_pre_execute

Maybe using hook__search_api_query_alter could d othe trick but I dont know how to implement it.

My question is : How can I achieve this ?

Knowing that I need to add anoteh condition only when items of a specific facet are active (among a few other facets).

  • I did find a simple solution using views UI and a new filter. No need to add a SQL condition. I have to put a filter using a specific field with the condition "IS NOT EMPTY". The if results do not validate my condition, they arent displayed. This is what I wanted but now I need to add this filter only when a specific facet has active item(s).
    – Math666
    Dec 20, 2014 at 9:29
  • Ive managed to add my filter using hook_search_api_query_alter and the code $base_filter = $query->createFilter('AND'); $base_filter->condition('field_produit_ingredients:format', NULL, "<>"); $query->filter($base_filter); But I don't know how to add this filter only when the specific filter is active. Theres a lot of things in $query ... so much that I can't dsm() it. And print_r rendering is so ugly !
    – Math666
    Dec 20, 2014 at 9:44
  • I could do that using FacetApiAdapter functions (drupalcontrib.org/api/drupal/…) ... I need help to be able to use one of these function within hook_search_api_query_alter. Anyone knows how to ?
    – Math666
    Dec 20, 2014 at 9:55

1 Answer 1


The solution is quite simple :

function mymodule_search_api_query_alter(SearchApiQueryInterface $query) {
        $base_filter = $query->createFilter('AND');
        $base_filter->condition('MYFIELD', NULL, "<>");

  • The Facets module lets you make facets dependent on other facets.
    – Kevin
    May 16, 2022 at 23:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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