2

I want to customize the default value for a filter in view through some custom code. I have tried the below answer and its not working for me.

if ($form['#id'] == 'MY_EXPOSED_FORM_ID') {
// Modifications go here.
// example: (change the field name to yours)
// $form['field_adv_cat_1_tid']['#default_value'] = 'All';

}

How to change views exposed filter default value

And I tried these settings also.

$form_state['input']['field_program_tid'] = '44';
$view->filter['field_program_tid']->value = "44";
$view->exposed_input['field_program_tid'] = "44";

Anyone help me in this?

0

1 Answer 1

2

you can try using hook_form_alter in your custom module.

     function yourmodule_name_form_alter(&$form,&$form_state,$form_id){
//print $form_id to get correct id of the exposed form
    if($form_id == 'views_exposed_form'){
      $form['field_program_tid']['#default_value'] = '44';
//you can unset "all" if you don't need it
      unset($form['field_width_value']['#options']['All']);

     } 
    }
2
  • Hi Thanks for the answer but I used contextual filter and its working fine.
    – elan
    Commented Jul 21, 2016 at 12:42
  • cheerio..thats also a clean way...
    – Deb
    Commented Jul 21, 2016 at 14:06

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.