I have a view which has a term reference exposed filter.
I want to set the default values of this exposed filter programmatically based on a certain condition.
I have tried the following code but the values are not selected in the filter.
function example_views_pre_build(&$view) {
if ($view->name == 'events') {
$tids = array(5, 6);
foreach (tids as $tid) {
$view->display[$view->current_display]->handler->handlers['filter']['field_category']->value[$tid] = $tid;
}
}
}
AND
function example_views_pre_view(&$view, &$display_id, &$args) {
if ($view->name == 'events') {
$tids = array(5, 6);
foreach (tids as $tid) {
$view->display[$view->current_display]->display_options['filters']['field_category']->value[$tid] = $tid;
}
}
}
I also tried with form_alter
, in form alter the values gets selected in the filter but then it does not display correct results after removing/applying again the filter.