4

I have built a module so that I can display PDFs with phpwkhtmltopdf. I am currently calling my view data using:

$view = views_get_view_result('course_catalog');

My question is, is there a way to have filter my exposed filters with this function? If not, what is the best way to go about this? --I suppose I could manually filter through the results with PHP, but that hardly seems efficient.

1 Answer 1

4

It seems views_get_view_result does not allow setting filters: https://www.drupal.org/node/1428696

Instead of using views_get_view_result, you might try with other functions of the Views API:

$view = views_get_view('course_catalog');
$view->set_exposed_input($my_exposed_input);
$view->init_display();
$view->pre_execute();
$view->execute();
$result = $view->result;

You can check the documentation for the set_exposed_input method, and also this related Drupal Answers question, for alternatives: How to change programmatically exposed filters in views

1
  • 1
    As the documentation is a bit short, I'd add that $my_exposed_input should be of the form array("my_filter_label_1" => some_value, etc.). Commented Jun 2, 2017 at 12:12

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.