0
votes

I am trying to filter a view of Biblio nodes via Author ID. On the staff profiles, I have a field (field_author_id_ccsi) which contains the ID (an integer). How can I reference that via PHP in the contextual filter for views (under Advanced). Here's what I have so far but it's not working:

$node = node_load(arg(1));
if($node->field_author_id_ccsi[und][0]->value)
   return $node->field_author_id_ccsi[und][0]->value;
} 
else { 
   return; 
}
2
Have you dumped out the data structure to ensure you're calling it correctly? For starters, it should probably be ['und'] not [und]... - ceejayoz
I think so. I used Devel to get the [und][0] part - solerous
Try returning print_r($node->field_author_id_ccsi, true) to get a dump of the structure. - ceejayoz

2 Answers

1
votes

You will need to open up you array object $node->field_author_id_ccsi to see where you ID is located and then drill down to it.

For example: Let $node->field_author_id_ccsi['und'] be your array of interest. You will need to investigate the contents of said array to see what is actually in that array. If you ID is the first element in the array then:

echo $node->field_author_id_ccsi['und'][0];

will show the integer on the screen in your view.

However a var_dump($node->field_author_id_ccsi['und']); will show you exactly where you ID is located - if it is there, as will a print_r();. You may need to use a foreach() to traverse the array if it is a multi-dimentional array.

0
votes

Here's the code I used which works:

$node = node_load(arg(1));
if($node && isset($node->field_author_id_ccsi)) {
    return $node->field_author_id_ccsi['und'][0]['value'];
}
return;