Author image
Senior Mind

Displaying exposed filter form for views in Drupal 6 (views 2)

One of the joys of working with Drupal 6, and views 2, is that you have to relearn a lot of things you used to take for granted ... one trick we use in most projects is embedding views filters in blocks, nodes or custom code. There are plenty of scenarios this is useful, the classic being to create a flexible views based replacement for the normal Drupal search. Anyway, enough of the blurb - heres the good stuff - some code to give you the filter form for a Drupal 6 views 2 view.

  $view = views_get_view('your_view_name');
  $view->set_display('default');
  $view->init_handlers();
  $form_state = array(
    'view' => $view,
    'display' => $view->display_handler->display,
    'method' => 'get',
    'rerender' => TRUE,
    'no_redirect' => TRUE,
  );
  $output = drupal_build_form('views_exposed_form', $form_state);
  return $output;