Advertising sustains the DA. Ads are hidden for members. Join today

On this page

Embedding an exposed form filter

Last updated on
30 April 2025
/**
 * Returns the exposed filter widgets for a view.
 *
 * @param mixed $view
 *  Either a string with the name of the view or an object of the view
 * @param string $display_id
 *  An optional string with the name of the display for the view.
 *
 * @return string
 *  The themed exposed filter form.
 */
function embed_views_exposed_form($view, $display_id = '') {

To figure out the id of a display, look under Other, in the
view edit page for the particular view that will be embedded, for
Machine Name what ever this name is is what should be used
for the $display_id variable.

Usage

Simple version of code to embed an exposed filter.

  print embed_views_exposed_form('test', 'embed_1');

Embedding a view's exposed form for an already created view using the
embed_views_exposed_form() helper function.

  $view = views_get_view('test');
  $view->set_display('embed_1');
  print embed_views_exposed_form($view);

  ... some other code ...

  $view->destroy();

Embedding a view's exposed form for an already created view using the
display's embed_views_exposed_form() helper method.

  $view = views_get_view('test');
  $view->set_display('embed_1');
  print $view->display_handler->embed_views_exposed_form();

  ... some other code ...

  $view->destroy();

Help improve this page

Page status: Not set

You can: