I'm using facet api with search api and SOLR. This all works as expected.

For non-search pages I use the views facet block and this displays the facets as required.

What I want to do though is have some of the facets pre-selected on non search pages.

For example: I have a views page: example.com/london I would like to show facets with 'london' preselected as if I was on a search page for london.

I've tried using a contextual filter on the views facet block and it half works. It shows only the selected city BUT the facet checkbox isn't checked; and if I click any of the other facets it does not show results filtered by city...

Any suggestions how I can get this to work?

  • OK. I can get the behaviour I want by hacking facetapi/plugins/facetapi/adapter.inc and substituting my own parameters into setParams(). I really don't want to go down this route but can't seem to find a way to access the adapter object early enough. I did manage to set the parameters without hacking but it seemed to fire after the facets were built. Commented Mar 5, 2018 at 14:55

1 Answer 1


So, despite the overwhelming response ;) after about 20 hours of banging my head against the desk I have this figured. I'm not sure if it is the most efficient way to do this, but I don't think the overheads are massive.

I did end up hooking into the adapter class but I couldn't find a facetapi hook that was called at the right time. In the end, I used hook_init.

You will need to get your parameters ($SOME_ID_VARIABLE) into the code. I used the current URL via request_path() and got node IDs from this.

The important bits of the code looks something like:

function MY_MODULE_init(){
  $searcher = 'search_api@MY_INDEX';
  $adapter = facetapi_adapter_load($searcher);
  $param_arr = array();

  $param_arr['f'][] = 'field_WHATEVER_FIELD:'.$SOME_ID_VARIABLE;
  $param_arr['q'] = 'VIEWS_SEARCH_PAGE/search';

Oh, and you still need to use a views facet block to get the facets to show up on the non-search page. I have used some caching on this block and everything still seems to work as expected.

The info on this page got me going in the right direction.

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.