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

Get the result of a view.


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.


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


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)) {
    if (is_string($display_id)) {
    else {
    return $view->result;
  else {
    return array();


koppie’s picture

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

koppie’s picture

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

ocastle’s picture

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). 
turbogeek’s picture

Arguments can be passed as additional parameters (as stated in the docs), so no array is needed.

ie: views_get_view_result($view, $display, $arg1);

prsnjtbarman’s picture

Passing the view's contextual-filter value as the arguments works fine for me

W.M.’s picture

Is it possible to pass exposed filters (not contextual) to this function? Thanks.

blakefrederick’s picture

Per https://groups.drupal.org/node/131029 and my own testing, views_get_view_result() does not return derived fields – it will only return fields present in the database. It's not clear to me how to use this function to retrieve derived fields. The linked thread suggests using hook_view_pre_render(), but this is not suitable in my case since I'm not rendering anything, I'm just outputting views data to CSV.

W.M.’s picture

This returns the results of the first page if using a pager. Is there a way to get all the results (without any pagination limits)?

golubovicm’s picture

Clone your display, remove pagination on clone and use it like that.

kalaiselvann’s picture

Is it possible to get pagination with rows ?