Author of question flags only nodes that are answer to his question (node reference) I have 2 node types - questions as parents and answers as referencing nodes. I would like to display flags only for nodes created as an answer to a given question. This should be only selectable by the author, not everyone.(same as stackoverflow best answer) So far I found out that I can manually place in node-answer.tpl.php the link using:

&lt;?php print flag_create_link('select_answer', $node-&gt;nid); ?&gt;


This will print the flag on every answer node, but I would like it to be selectable only by the author of this particular question. (basically it is the same functionality as stackoverflow - author can select best answer) There is an API function flag_create_link($flag_name, $content_id), so I need to set $content_id to point to all referenced answers for a given question. 

ANy idea how can I do it? Any advice appreciated.
Are they 2 nodes or 2 node types? If types, just create 2 separate .tpl files for them (node--type1.tpl.php and node--type2.tpl.php).

If they are the same content type, you can check that the node reference exists inside node.tpl.php like so:

Edit: code below now only prints the link if the current user is also the author of the node.

global $user;
if ($user-&gt;uid == $node-&gt;uid &amp;&amp; isset($node-&gt;field_my_reference_field_name[LANGUAGE_NONE)) {
  print flag_create_link('select_answer', $node-&gt;nid);
}