Here is the situation:

I have two content types. Content type a has a CCK reference field for content type b.

Now I am trying to load all the nodes from content type a that are referenced to content type b.

Here is the code that I have.

$nidcur =  $fields['nid']->content;

$node = node_load(array("field_micselect" => $nidcur));


So I would like to load all the nodes that are related to the nid $nidcur.

1 Answer 1


This should work for you:

$referenced_nodes = db_query("SELECT `field_FIELD_NAME_nid` AS `nid` FROM {content_field_FIELD_NAME}");
while ($referenced_node = db_fetch_object($referenced_nodes)) {
  $node = node_load(array('nid' => $referenced_node->nid));
  // Do your stuff here
  • It worked. thank you very much. Here is the code again. I added the posibility to tell which nid you are looking for. Hopefully it helps somebody ;) $nidcur = $fields['nid']->content; $referenced_nodes = db_query("SELECT field_FIELD_NAME_nid AS nid FROM {content_field_FIELD_NAME} WHERE field_NAME_nid = " . $nidcur); while ($referenced_node = db_fetch_object($referenced_nodes)) { $node = node_load(array('nid' => $referenced_node->nid)); }
    – wolfmarter
    Commented Sep 19, 2012 at 12:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.