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.

Comments

drupalisme’s picture

Try this:

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

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

$sc=$_GET["sc"];
$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!

iancawthorne’s picture

You could try:

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

Then use the $node info.

johnv’s picture

Status:Active» Closed (duplicate)
clevername’s picture

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.

turingfan’s picture

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.

<?php
$account
= 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'] ){ 
    return
TRUE;       // filter out this row
}
?>
AaronELBorg’s picture

...

gregory_kapustin’s picture

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 :)

gregory_kapustin’s picture

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.

steveoriol’s picture

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

ChrisValentine’s picture

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

Woot!

monaw’s picture

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

PLEASE FIX!

matthieu_collet’s picture

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....

agerson’s picture

Issue summary:View changes

Also worked around it with node_load.

idkelly’s picture

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

imclean’s picture

Same issue: #1222448: Views PHP Can't Filter

I've marked that one as a duplicate as this one is older with more people following it.

Renee S’s picture

Confirmed. The $row values are there, but that's it. $data is empty.

In Global:PHP for field value, the value also is missing the pertinent view information, again: $row values are there, but $data is empty. Only in the output box on the filter are all the values present as advertised.

imclean’s picture

vulfox’s picture

Priority:Normal» Major

I just used about 6 hours of trying to get this to work.

What do you think.. Is this module something that could be used?

Alternatives?

vulfox’s picture

Category:Support request» Bug report
CProfessionals’s picture

I tried #1 and could not get it to work so I applied the following with the 'und' and all is working... Thanks for all who contribute

<?php
$node
= node_load($data->nid);
$zipcode= $node->field_zipcode['und']['0']['value'];
If (
$zipcode == "USA-11784") { return FALSE;} else {return TRUE;};
?>