I’ve got a random cached view that I need to access the elements of without displaying it to get the order into a session for some next/prev buttons to work.
When I output the view using views_get_view I get totally different results to the actual display. Any ideas?
$view = views_get_view('hotels_view');
$view->set_display('block');
$view->render();
print sizeof($view->result);
$counter = 0;
foreach ($view->result as $result) {
echo 'Result: ' . $result->nid . ' -- ' . url( 'node/' . $result->nid, array('alias' => FALSE)).'<br />';
$counter++;
//$_SESSION['hotels_listing'][$counter] = url( 'node/' . $result->nid, array('alias' => FALSE));
}
I have not tested this locally, so just some speculations:
First up, I’m not sure if this changed from D6 to D7, but IIRC, the display ids always have a number attached, so I’d expect the need to use ‘block_1’ instead of just ‘block’.
Further on, looking at the
render()function, it expects the display id as a parameter. If I read the code correctly, it will not check for the id set via$view->set_display(), so this might lead to a different (namely the default) display being used, which would result in a different cache result being used.So you might try again like so:
In case that works, you might also want to save some processing time by omitting the rendering, as you are only interested in the query result order, not the actual output: