0

I want to add an exposed filter to a view which contains already exposed filters but without altering them. When I add the following code it messes up the exposed filters from the view and only the programmatically coded exposed filter works correctly.

I use the following code:

function music_m_views_pre_view(&$view, &$display_id = null , &$args = null) 
{
$filter = $view->display['default']->handler->options['filters'];       
$current_latter = arg(1);      
$filter['field_last_name_value']['value'] = $current_latter;

$view->display_handler->override_option('filters', $filter);
}
0

The hook function used was wrong. I had to use hook_views_pre_build(&$view) so I have now the following (and the other exposed filters don't get messed up):

 function music_m_views_pre_build(&$view) {

$view_filters = $view->display['default']->handler->options['filters']; 

 $current_latter = arg(1); 

 if($current_latter)
 {  
    $view_filters['title']['value'] = $current_latter;  

 } 
$view->display[$view->current_display]->handler->handlers['filter']['title']->value = $current_latter;

}

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.