So, I have got a node reference field, which can have multiple values and I'm attempting to compose a php code, which will check all values of that field for a certain value i want and print a text if it finds it. I want to do it in views php field and this is the code i have came up with so far:
<?php
$node = node_load($data->nid);
print $data->nid . '<br>';
if(in_array('Yog [nid:1315]', $node->field_ref_oznajomenieni)) {
print 'yoog';
}
else {
print 'niemanic';
}
?>
I'm somewhat bad in PHP, but:
The node_load()
works fine and $data->nid
returs node id for every row of my view.
This is confirmed by print $data->nid . '|';
Now, the if function is supposed to do what i want, search the array of values for something in the node reference field and print something too.
I'm not sure if i should search for the nid of the referenced node, its title or how i put it in the code, whatever i try, i get the print 'niemanic';
of the else{}
How should i do it exactly, please?
To make it clear: The code is to search for a value in a node reference field and print something only if it is found.
one way:
another way: (untested, may lack some brackets)
Here is what i have figured by myself:
This is
print_r($node->field_ref_oznajomenieni);
output of an example field: