Hi there, pretty simple question, hope I can get a relatively straightforward answer :)

How can I use the result count from a view (the actual number) somewhere else on the site (like in another view, using Custom Field)? I would imagine it has to do with running the view, and then grabbing the result, of which you can get the total result count, but I'm not sure how to do that, and I'm not sure if this method would be "global", i.e. I could run it from pretty much anywhere on my site and it would work (say, in a block or a template preprocessor), so any help you could give would be excellent. Thanks!

Comments

dawehner’s picture

Status: Active » Fixed

You can get the total count of a view with

$view = views_get_view('viewname');
$view->get_total_rows(TRUE);
$output = $view->preview();
print $view->total_rows;
SpikeX’s picture

Status: Fixed » Closed (fixed)

Thanks! :)