Advertising sustains the DA. Ads are hidden for members. Join today

Computed Field

Show title of parent node in node heirarchy

Last updated on
30 April 2025

here is the code to solve this:

Hierarchy:
TypeA
-TypeB (has nodereference field typeb_to_typea) this field shows the name of node a
--TypeC (has nodereference field typec_to_typeb) this field shows the name of node b

install Computed Field module, make a computed field in content type typeC, and put this in it:

$mytempvar=db_result(db_query("SELECT
field_typeb_to_typea_nid FROM content_type_typeb WHERE
nid=%d",$node->field_typec_to_typeb[0][nid]));

$node_field[0]['value']=db_result(db_query("SELECT title FROM node WHERE nid=%d", $mytempvar));

(returns node Title) Note: look at Hierarchy above and depending on what fields you use in your content types and what their names are, you will have to change
field_typeb_to_typea_nid
to
field_your_field_name_nid (attach the _nid to whatever the name of your field is, your field should start with field_ no matter what)
also
content_type_typeb
to
content_type_yourtype (content_type_ + whatever your type is)
also
field_typec_to_typeb
to
field_your_field_name (your field should start with field_ )

if you want to return the node Number/ID instead, do this (same field name rules apply to this as the code above):

$node_field[0]['value'] = db_result(db_query("SELECT
field_typeb_to_typea_nid FROM content_type_typeb WHERE
nid=%d",$node->field_typec_to_typeb[0][nid]));

(returns node ID #)

Help improve this page

Page status: Not set

You can: