function views_get_view_result

You are here

7 views.module views_get_view_result($name, $display_id = NULL)
6 views.module views_get_view_result($name, $display_id = NULL)

Get the result of a view.

Parameters

string $name: The name of the view to retrieve the data from.

string $display_id: The display id. On the edit page for the view in question, you'll find a list of displays at the left side of the control area. "Master" will be at the top of that list. Hover your cursor over the name of the display you want to use. An URL will appear in the status bar of your browser. This is usually at the bottom of the window, in the chrome. Everything after #views-tab- is the display ID, e.g. page_1.

...: Any additional parameters will be passed as arguments.

Return value

array An array containing an object for each view item.

File

./views.module, line 2220
Primarily Drupal hooks and global API functions to manipulate views.

Code

function views_get_view_result($name, $display_id = NULL) {
  $args = func_get_args();
  array_shift($args); // remove $name
  if (count($args)) {
    array_shift($args); // remove $display_id
  }

  $view = views_get_view($name);
  if (is_object($view)) {
    if (is_array($args)) {
      $view->set_arguments($args);
    }
    if (is_string($display_id)) {
      $view->set_display($display_id);
    }
    else {
      $view->init_display();
    }
    $view->pre_execute();
    $view->execute();
    return $view->result;
  }
  else {
    return array();
  }
}

Comments

Helpful tip: arguments must be in the form of an array. Eg.:
views_get_view_result($view, $display, array(3));

Helpful tip: arguments must be in the form of an array. Eg.:
views_get_view_result($view, $display, array(3));

I don't think that's always true.

I'm embedding a view with a single argument of 'content: type' and if I use an array instead of a string i get the following errors:

Warning: Illegal offset type in isset or empty in node_type_get_name() (line 462 of modules/node/node.module).
Warning: html_entity_decode() expects parameter 1 to be string, array given in decode_entities() (line 459 of includes/unicode.inc).