I'm writing an action to be invoked upon child node creation... How could I refer and update a parent node's field (e.g. 'total').

Many thanks in advance.

Comments

andrew7’s picture

I meant the php code for pointing to the CCK fields... Anybody?

darius’s picture

$nid = 95;
$node = node_load($nid);
$parent = node_load($node->parent_node);
print $parent->field_some_cck_field;

devel.module is useful for such stuff.

darius’s picture

Status: Active » Fixed
Anonymous’s picture

Status: Fixed » Closed (fixed)
gaia’s picture

Sorry, I have to reopen this issue. I can´t get this to work. Tried to implement this

$nid = 6;
$node = node_load($nid);
$parent = node_load($node->parent_node);
print $parent->field_some_cck_field;

in my template, but nothing appears in my content-type. Can somebody give me a hint, what i´m missing.

I also tried to embed a View with the Argument Type "Relativity: Parent Node ID" and my CCK Field, but this isn´t working either.

Any Help would be appreciated. Thank you in advance.

gaia’s picture

Version: 5.x-1.x-dev » 5.x-2.2
Status: Closed (fixed) » Active

Sorry, forgotten to change status

gaia’s picture

Nobody? this is very important for me to finish a project. Any help would be appreciated.
THX in advance.

darius’s picture

print $parent->field_some_cck_field; was not meant to be typed literally. Replace it with whatever field you need to access.
Use devel.module for testing and running php code; using templates add another layer of complexity and makes it harder to find bugs.

Jeff Burnz’s picture

I found the above code gave me errors in node.module.

I recently used this code to print an image (imagefield field) from the parent node in all its children. I couldn't see how to get the value but the filepath and alt are there to grab. As mentioned above use the Devel module, its a great help.

<?php if ($parent_node) {
$nid = $parent_node; 
$parent = node_load($nid);
print '<a href="?q=' . $parent->path . '">' . '<img src="' . $parent->field_logo[0][filepath] . '"' . 'alt="' . $parent->field_logo[0][alt] . '" />' . '</a>';
}
?>
Jeff Burnz’s picture

Actually, in the end this is what I used...

<?php 
  $nid = $parent_node; 
  $parent = node_load($nid);
  $path = drupal_get_path_alias("node/$nid");
  print '<a href="http://localhost/tr/' . $path . '">';
  print theme('image', 'files/imagecache/logo/'. $parent->field_logo[0][filepath]);
  print '</a>';
?>