I have a page with a view on it and some exposed inputs. I need to get the results programatically. I can load a view programmatically no problem but setting the exposed input has not been working.

$view = Views::getView('inventory_listing');

results in ALL the rows, not the ones filtered out. I am running this in my hook_form_alter function because I need to change the display of my exposed filters. That may be part of the problem. Any ideas?

1 Answer 1


I use direct input parameter for right filtering, and it is working for me.

$view = Views::getView('my_view_name');
$view->setArguments([ $value1, $value2 ]);

So, i can take result of $view by

$result = [];
if (empty($view->build_info['fail']) and empty($view->build_info['denied'])) {
    $result = $view->result;

After this I can render it or use for another goal.

Your Answer

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

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