I'm writing a queued cron process, and need to retrieve some information while doing this. Rather than fiddling around with DB queries, it seemed to me much easier to create a View and then execute it in the code. Which I did (and by the way, the View itself works fine and returns the expected result). Trouble is, although it seems to run fine, it returns no result.

I've tried two different ways of doing this, but both are the same: the result is empty.

First was very simple:

if (!isset($node->og_group_ref)) {
  $regions = views_get_view_result('og_regions');

That left $regions empty, so I tried this, with no better result:

if (!isset($node->og_group_ref)) {
  $view = views_get_view('og_regions');
  $regions = $view->result;
  • 1
    And your if condition is correct?
    – Huelfe
    Nov 10, 2015 at 9:10
  • Yes, the if condition is fine, I have checked this running in debug. I think maybe the problem comes from permissions running in cron, having looked at this blog post. I'm not sure where to place this instruction though, since I'm running from a worker callback called by hook_cron_queue_info.
    – Martin K
    Nov 10, 2015 at 23:50

1 Answer 1


Problem sorted. It was all down to permissions, and loading user 1 as described in the blog linked to by my previous comment allowed the View to work as expected.

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.