I am far from a newbie, but this IS the first time I have tried to access a CCK text field inside a node and I am having serious difficulties, so please help!

I have a CCK field, lets call it field_myfield. I want to pass that field via a php snippit in the body back to a function in a custom module (which is not the issue here). I have tried many permutations, but cannot get access to the field, even just to echo or print it out.

I have tried:
print $node->field_myfield; // as far as I can see this should work(?)
print $field_myfield;
etc.

Nothing I have tried returns the (verified) content of this already filled-in field.

It must be right in front of my face, but I just can't see it.

Any help would be greatly appreciated!

Comments

nevets’s picture

From what you say it sounds like you are trying to access the field from within the body of the node. If that's the case there is no constantly reliable way to do that, PHP code in the body does not have access to the node.

As for the field, assuming $node is actually set to an instance of the node, $node->field_myfield is an array. Depending on context, $node->field_myfield[0]['value'] should work.