hi everyone

I have a node list with their IDs and I have to get them one by one. How can I get them with single step and get their fields?

I mean I have node ids : 21, 23,45 ..etc
I want to get a list of all nodes information in one object like below :

21:
title : "21's node title"
23:
titl2: "23's node title"
45:
title: "45's node title"

otherwise I have to access them one by one with node.get

how can I do that?

best regards

I have 6.1.4 drupal
I use AMF PHP

Comments

johnhanley’s picture

As you suspected you'll have to get them one by one:

$nids = array(21, 23, 45);
foreach ($nids as $nid) {
  $node = node_load($nid);
  print t('!nid's node title is "!title"', array('!nid' => $node->nid, '!title' => $node->title));
}

You could also build an array of objects indexed by nid:

$nodes = array();
$nids = array(21, 23, 45);
foreach ($nids as $nid) {
  $nodes[$nid] = node_load($nid);
}
return $nodes;

This assumes you're writing custom code to be used in a module or snippet. If not you're better off using Views.

joecanti’s picture

If i've understood correctly views would do this very well...you could also add filters/different content types so that you only got the ones you needed, but you could build up a list of different node content + fields on the same page..

cheers, Joe