Drupal 6 revisted: Passing arguments through filters in Views

This Comment will be submitted for moderation and will not be accessible to other users until it has been approved.


<?php
$view = views_get_view('view_name');
// fetch the view

$display_id = 'default';
// chose the display type

$view->set_display($display_id);

$view->is_cacheable = FALSE;

$item = $view->get_item($display_id, 'filter', 'distance');// telling the view that we are fetching filter.  distance is the filter name. We can check the filter name from view export as well.

$item['value'] = array('postal_code'=>'00210', 'search_distance'=>'100', 'search_units'=>'mile'); // passing values to all the exposed filter. We can pass other options like operator etc (not just value) as well.

$view->set_item($display_id, 'filter', 'distance', $item); // set item

$view->is_cacheable = FALSE;

$output = $view->render();
// render

print $output; // display output

?>

                                     

Post Comment

  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <c>, <cpp>, <drupal5>, <drupal6>, <java>, <javascript>, <php>, <python>, <ruby>. Beside the tag style "<foo>" it is also possible to use "[foo]". PHP source code can also be enclosed in <?php ... ?> or <% ... %>.