I have a site which shows paintings by artists. On each painting page there is a section called 'related paintings'. This is a related field which provides the admin user the ability to tick other related paintings.
I would like to tick paintings by the same artist by default, so admin doesn't have to do it. I initially did this and it works, but obviously only ticks one painting:
return array(
0 => array('nid' => '278')
);
Then I tried this, which does work in a template, i.e. it produces an array in the right format:
$artist_nid = $node->field_artist[0]["nid"];
$artist_paintings = node_load($artist_nid)->field_painting_nodes[0] ["items"];
$a = array();
foreach ($artist_paintings as $painting) {
$a[] = array('nid' => $painting["nid"]);
}
But this doesn't work when called, I get the error:
warning: Invalid argument supplied for foreach() in /home/will/sites/modernprints/www/sites/all/modules/cck/content.module(2220) : eval()'d code on line 4.
I'm guessing that $node doesn't exist or something in that context? What variables are available?