I am currently working on a website that requires a view that should be filtered based on time. It is for a radio station. I have a view that is suppose to show the program that is currently broadcasting. I use a content type that has a basic integer field for the hour. I've tried to use the php filter to do the following.

$current_hour = date('G');

$hour = $data->field_field_program_schedule_shour[0]['raw']['value'];

if ($hour == $current_hour)
return false;
} else {
return true;

I should point out that I have tried using the variables that are given in the list, but they do not work. I thought the "$data->field_field_program_schedule_shour[0]['raw']['value']", which does work in a php field, would work in the filter also, but no matter what I try, I can't get the value of any of the cck fields.

My question is how can you get the value of the cck fields into the php filter textarea field and use that value to filter the view.

I am using Drupal 7.


Try this:

$node_program = node_load($data->nid);
$hour = $node_program->field_program_schedule_shour[0][value];

I have the same issue. I have added the following code to the filter and its not working. It should be right?

$client_account = $data->_field_data['nid']['entity']->field_customer_account['und'][0]['value'];
if ($sc == $client_account)
{return false;}
else {return true;}

How can we pull the data from a field? I know there are issues with getting the correct content using the variables, but I thought we pulled in using the above syntax rather than the variable it would work. Any suggestions on creating filters would be appreciated, since I can't get anything to work in this field!

You could try:

$node = node_load($data->nid);

Then use the $node info.

Status:Active» Closed (duplicate)

After hours of struggle, #1 worked for me, but not #4. The solution proposed in #1140896: Variable $row does not contain correct values ($data->_field_data does) seems to only work for Views PHP as a field, not a filter.

I'm sure this was mentioned before somewhere, but after banging my head over this issue I figured out how to use the Devel module to debug just the "PHP filter code" variables by calling "dpm($data);"

I found that $data and $row don't contain the same fields as they do in the "PHP field output".
So for now, I'm using the only useful variable $data->uid which as the user ID of record I want to evaluate.

= user_load($data->uid);       
$term_loc= field_get_items('user', $account, 'field_location');   
$term = taxonomy_term_load($term_loc[0]['tid']);
if( isset(
$term) && $term->name <> $static['city'] ){
TRUE;       // filter out this row


Hi guys,
I'm having the same issue, and using a node_load seems to me a little bit bad for performances...

Which is the weirdest is that we already have a few data gathered from the DB at this stage : nid, node title...

Thus, for my part I build most I can in Setup Code, in order to obtain, at the end, an array of nids that I put in $static, allowing me to do only if(!in_array($row->nid, $static)) {return TRUE;} in the row (Filter Code).

This often requires some db_query in the process : that's where I save the node_load pain.

But still not as good as this issue was solved :D

So, subscribing :)

Status:Closed (duplicate)» Active

By the way, I'm setting this issue back to active, because it's indeed NOT a duplicate, as said in #5 : we can access what we want when the PhP is as a field, not as a filter.

This bug it's a pain, i hope it will be fix soon :)

Hope so too - using PHP in filters is turning out to be a right pain.

$row certainly doesn't work - so ignore what it says in the "Available variables" dropdown.

$thisData=$data->_field_data['nid']['entity']; - works just fine in a field but causes errors in a filter.

$thisNode = node_load($data->nid); - works in a field but also works in a filter


Doing a node_load() is a big performance hit since you have to reload each node again!


Yeah this bug is awful :(
in my case node_load() doesn't work because I'm with a file, and additional fields added with media :( impossible to retrieve....

Issue summary:View changes

Also worked around it with node_load.

Same problem here. I was able to get around it with node_load as mentioned several times above, but have noticed that pagers then don't work properly. Pagers seem to count items filtered out. i.e:

- paging is set to 10 items per page, but only 8 are shown
- entire pages will be blank