I'm trying to call views_get_view_result from a block class to load in a view. My view has two contextual filters (one for a year, one for state of node). So I'm trying to call views_get_view_result like so:

views_get_view_result([view_machine_name], [view_display_name], $arg1, $arg2);

All I get back is an empty array. The view does have default values set for the contextual filters, and when I remove the extra arguments, ex:

views_get_view_result([view_machine_name], [view_display_name]);

I get values back from the function as I would expect. What am I doing wrong with the additional parameters?

  • Do you have any special validation configured for the contextual filters? If you test in the views ui passing the same arguments does the preview view render your expected results? – sonfd Jan 29 at 19:14
  • 2
    Try with views_embed_view instead. – No Sssweat Jan 30 at 6:02
  • @sonfd, good call, the view was built so that the contextual filters never actually worked (parents didn't seem to to know children in relationships). I rearchitectured it, and the contextual filter worked, but views_get_view_result didn't work. – Jance Jan 31 at 17:10
  • @NoSssweat, I did end up using views_embed_view, and that seems to work really well with Drupal 8's rendering system. If you wanna add that as an answer, I'll go ahead and accept it. – Jance Jan 31 at 17:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.