Calling a view from code gives no results 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-&gt;set_arguments( $account-&gt;uid ); 
$view-&gt;build('block_3');
$view-&gt;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?

Some notes

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 $view-&gt;result to dpm(), I get empty text; dpm($view) returns the $view object, where I can see that $view-&gt;result is an empty text.
The View set_arguments() method takes an array as it's first parameter; currently you're passing a string/int.

This code will work.

$view-&gt;set_arguments(array($account-&gt;uid));


I think you're right about the C-style access to a string-as-an-array-of-chars in PHP. The following code prints the letter e, which would certainly support that theory.

$x = 'test';
print $x[1];


I must say I'm surprised that Views doesn't check the validity of the parameter passed to it, but hey ho!