Update at 2015-04-27: Another suggestion by Petu which could render the filter as a block programmatically.
Update at 2014-09-18: An simpler way to do that is to enable the Exposed form in block in the view settings and then render the block as suggested by plano.com.
The following piece of code render the Views Exposed Filter.
$view = views_get_view('<view name>'); $display_id = 'page'; $view->set_display($display_id); $view->init_handlers(); $form_state = array( 'view' => $view, 'display' => $view->display_handler->display, 'exposed_form_plugin' => $view->display_handler->get_plugin('exposed_form'), 'method' => 'get', 'rerender' => TRUE, 'no_redirect' => TRUE, ); $form = drupal_build_form('views_exposed_form', $form_state); print drupal_render($form);
4 thoughts on “Drupal 7 – Render Views Exposed Filter programmatically”
Much more easiest way is:
Select the Exposed form option as “Exposed form in block : Yes”
by exposing the selected fields under the “Filter Criteria”.
Great tips. thanks! =D
More correct way is:
Where ‘-exp-search_page-page’ is a block delta. It may be taken from URL on block editing page.
Thanks! i have updated the post.