By RichieRich on
Hi there,
I've got a CCK filed called 'field_myfield' and I'd like to gain access to its value as efficiently as possible. I've found that I can do this by first calling the node_load function from within my node, however, I'm concerned that this is very inefficient as I'm loading all stuff related to the node.
Does anybody know of a better means of gaining access to this value than what I've done below? I'm a bit surpised that I can't access field_myfield without the node_load call. Note that I've inserted this code directly in the node.
<?php
$node = node_load(arg(1));
$test = $node->field_myfield[0][value];
?>
Thanks in advance, Rich.
Comments
The content of $node is
The content of $node is cached in a static variable and calling node_load() simply makes it all available to your code. Best way of getting it.
gpk
----
www.alexoria.co.uk
Thanks
I've just discovered that I can access the field directly in the node.tpl.php file which is great. In actual fact this is probably a better place for my code anyway.
So are you saying that there's essentially no overhead with making the node_load() call?
Where are you editing?
Where are you editing? Are you adding this from within the admin pages or going into the theme and adding the PHP?
...
I simply added the code to the node itself with the php filter enabled. I'm now moving stuff to the node.tpl.php (although I'll have a different version for the path / content type).
>So are you saying that
>So are you saying that there's essentially no overhead with making the node_load() call?
Correct, the node is loaded early on in the page request anyway.
gpk
----
www.alexoria.co.uk