i create a views : test_flashvideo
with a filter "node:type" expose;and the values i can choose are "any,flashvideo,test,dash";

in node.tpl.php:
i knew that "views_embed_view('test_flashvideol')" will display all the results of "node:type"="any" ,
but i just want to display "node:type"="dash".

yet , i knew that if i use a fillter as an argument , in this case , "node:type" as an argument ,i will just have to embed views_embed_view('test_flashvideol' , '' ,'dash');
but i don't want to create another views just function the same.

i found out some code through google, but they didn't work in my situation

$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

help ,please

Comments

merlinofchaos’s picture

Status: Active » Closed (won't fix)

Sorry, passing data to Views through arguments is supported. Other methods are not.

gagarine’s picture

Status: Closed (won't fix) » Fixed

You can use the API instead

function my_module_execute_view($filters = array()) {
  $my_content_view = views_get_view('view_name');
  $my_content_view->set_exposed_input($filters);
  $my_content_view->set_items_per_page(20);
  $my_content_view->set_use_pager(TRUE);
  $display = 'default';
  $my_content_view->build($display);
  $content = $my_content_view->render($display);
  return $content;
}

look at http://groups.drupal.org/node/10129

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

MohammadMoussa-Lebanon’s picture

hello every body ,im trying to make a website for sales, but im facing a problem which is , i have 3 categories apartments (for sale , for rent , to buy ) ,lands (for sale , for rent , to buy ) , buildings (for sale , for rent , to buy ) ,
all i want to do is to place 2 select boxes and let the user select in the first box if he want apartment or land or building and in the second box for sale or for rent or to buy and click a button which create a query and show all in the same page, i mean all results must be in the same page,please help me im a new drupal user ,its a hard problem:S:S:
thanks a lot