I'm trying to display some custom user fields of an author, of a content type's nodes. The only fields in $node that relate to the author seem to be $node->name
and $node->uid
. I tried this in node.tpl:
global $user;
print render($user->field_foo);
and it makes the field show up in Krumo, but it comes up as
field_foo (NULL)
When I get more specific, using what's available to me in the user page, $field_foo['und'][0]
in this case, I'm given something similar:
field_foo (Array, 1 element)
und (Array, 1 element)
0 (NULL)
I'm thinking I need to target the UID or name somehow, but I don't know how. What's described in the answer here sounds like what I want, but I'm not sure how to do what they're describing. It sounds like I should maybe be using a node_submit function. Something like this maybe?
function MYMODULE_node_submit($node) {
if (isset($node->name)) {
if ($account = user_load_by_name($node->name)) {
$node->uid = $account->uid;
}
else {
$node->uid = 0;
}
}
$node->uid->field_foo;
return $node;
}