Drupal: Retrieving views results with multiple arguments

In case this catches anybody else up, you have to access the results of a view with multiple arguments by passing the arguments in as a STRING in an array. Like this:


$nodereferences = array();
foreach ($vars['form']['#node']->field_nodereference as $reference) {
$nodereferences[] = $reference['nid'];
}

$imagepathview = views_get_view('my_view_name');
$imagepathview->init_display('default');
$imagepathview->set_arguments(array(implode(',',$nodereferences)));
$imagepathview->execute();
print_r($imagepathview->result);

Very odd, and I couldn’t find anywhere on the internet that tells you this, Igot it working by trial and error.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>