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

Computed Field

Reference a CCK field from a different content type

Last updated on
30 April 2025

If you have two different CCK content types and you want to reference information in one from the other, one way of doing that is to setup a nodereference field (in this example, field_application) that points to the related node.

Then create a computed field with the following:

<?php
$node_field[0]['value'] = db_result(db_query("SELECT field_phonenumber_value FROM content_type_content_enrollment_application WHERE nid=%d",$node->field_application[0][nid]));
?>

In this example, field_phonenumber_value is the name of the field from the other content type as stored in the database table for the other content type (table content_type_content_enrollment_application). You'll only have to modify the sql slightly to pull a field not tied to a single content type, like a table such as content_field_phonenumber.

Store the result in the database and set the type and size to match the type and size of the original field.

Why would you want to do this instead of just using nodereference to show the contents of the referenced node? Well, if you're creating a view, you may not want to make the view load every single node of the other content type when all you really want is to display the contents of one field.

Help improve this page

Page status: Not set

You can: