I have a view that I use to grab a related node field given a user ID. I only call this view from code. The problem is, I just can't get it to work for a certain case.
To start with, here's the code that I use to call the view. The view accepts one argument (the user ID) and displays one field (the related node field). (I use multiple displays in this view for different code functions, thus why I build 'block_3'. Also, I'm calling this code from within a "User has logged in" Rule, which is why I use $account instead of global $user.)
$view = views_get_view('my_view_name'); $view->set_arguments( $account->uid ); $view->build('block_3'); $view->execute();
For the user ID "5", this works perfectly. But for the user ID "14", it returns no results. The frustrating part is that in the View settings, I can enter "14" for the preview argument and it ALSO works perfectly!
I'm at my wit's end. Why would the view work perfectly fine in the preview and for one user ID, but not for another?
I've confirmed with
dpm() that $account->uid is being set properly. I've also changed User ID 14's roles to match User ID 5's, and even swapped the related nodes for the two accounts, but User ID 14 always fails to work while User ID 5 has no issues.
If I pass
dpm(), I get empty text;
dpm($view) returns the
$view object, where I can see that
$view->result is an empty text.