5

With Views in D6, I was able to get the results of a Views display as an array and work with it using php code embedded in a node.

For example, using this code snippet:

$view = views_get_view('view_name', 1);
$view->set_display('block_1');  
$view->preview();
$MyArray = $view->result;

This allowed me to get the results of the 'block_1' view display into the $MyArray array.

However, I'm trying to do the same thing in D7 and all I'm getting is a list of all the nodes in the view I'm calling, and not the results of the view display.

How do I get the results of a view display in code for D7??

1 Answer 1

5

I think it has been replaced by the views_get_view_result() function. It returns:

An array containing an object for each view item.

e.g.

$result = views_get_view_result('view_name', 'block_1');
2
  • Yes, that worked! The resulting array is a little bigger than I'd like but I was able to extract what I needed from it. Thanks!
    – yuhwei
    Commented Oct 26, 2012 at 21:24
  • 1
    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)?
    – W.M.
    Commented Feb 19, 2017 at 19:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.