I'm trying to write a conditional statement in a template file to check if the value of a 'node reference' field is not equal to a certain value. This is what I have so far:
<?php
$value = ( $content['field_collection_or_bespoke']['#items']['0']['value'] );
if ( $value != 'bespoke' ) : ?>
// Do something if not bespoke
<?php endif ?>
At the moment it is always evaluating to true. I'm not sure if $value
is not getting the correct field or that the value I'm testing against is wrong. If that's the case how can I find the values of the field_collection_or_bespoke
field?
Many thanks
Problem is probably in the incorrect reference:
$value = ( $content['field_collection_or_bespoke']['#items']['0']['value'] );
Language key is missing in the array.
It should be something like:
$value = ( $content['field_collection_or_bespoke']['und']['0']['value'] );
Please do Print_r($content['field_collection_or_bespoke']);
to get details.