Calling a view from code

$view=views_get_view(“VIEW_NAME”); //replace products with the name of the view created in step 1
$view->set_arguments(array($node->uid));
$view->build(‘default’); //use “default” if you want to retrieve the default display of your view, if not, the name of the specific display
$view->execute();
foreach($view->result as $result) { //$result
//  Do something with $result here.  Each result is an object, so for example you can access the nid using $result->nid
if ($result->node_vid){
drupal_goto(‘node/’.$result->node_vid);
}elseif($user->uid==$node->uid){
drupal_goto(‘node/add/portfolio’);
}else{
//drupal_goto(‘home’);
}
}

Reply