I am trying to embed a view using a php snippet, and then set the values of exposed filters, using the method explained here: http://groups.drupal.org/node/10129

I am using the following code and it works perfectly for exposed filters that only allow only a single selection.

<?php
   $view = views_get_view('view_name');
   $view->set_exposed_input(array('filter_name' => '10'));
   print $view->preview('default');
?>

But, this code will only work for single-option filters (i.e. when "Force single" is checked on the filter options). I also want to be able to set values for filters that allow more than one selection. Can anyone help with a code snippet that would work to set the value(s) of exposed filters that allow multiple options?

Thanks!

Comments

nancydru’s picture

I have pretty much the same situation with specifying the option value in the URL. It works fine on all the single choice filters, but not on the one multi-choice filter unless I set it to "Force single" which the customer doesn't want.

merlinofchaos’s picture

Multi-value filters need to have their values set as an array.

i.e

$view->set_exposed_input(array('filter_name' => array('10', '11', '12')));

Is that your problem?

nancydru’s picture

Thank you, Earl. Also, in URLs, I see they need brackets (?geo[]=76).

merlinofchaos’s picture

In a url ?geo[] = 76&geo[]=77 means: geo = array(76, 77) in PHP.

(Or more likely:

$geo[] = 77;
$geo[] = 78;
merlinofchaos’s picture

Issue summary: View changes

correcting typo

mustanggb’s picture

Issue summary: View changes
Status: Active » Closed (outdated)