Hi,

I want to grab the nid from an array (for example: array(1) { [0]=> array(1) { ["nid"]=> string(5) "32857" } } ) and load node using node_load.

How do I do that. I am trying but no success.

Thanks,

Ashish

Comments

mitchmac’s picture

You likely have a problem in the syntax you are using to get the nid. Let's see what you have tried so we can help you debug.

agsparta’s picture

  if($node->type == 'individual' && $node->field_site_node != NULL) {
      	
      	// Grab the lat/long coords
      
      	//$node = node_load(array("nid" => $node->field_site_node[0]['value']));
      	//$sitevalue == $node->field_site_node;
      	$site_nid = $node->field_site_node[0]['nid'];
      	$sitevalue = array("nid" => $site_nid);
      	//$node->nid = $sitevalue->nid;
       	$site_node = node_load($site_nid);

mitchmac’s picture

The syntax you are using to load the node is fine, but the if condition will evaluate to TRUE even if there is no reference nid because $node->field_site_node is likely an empty array (it's not NULL but is empty).

if($node->type == 'individual' && $node->field_site_node[0]['nid'] != NULL) {
agsparta’s picture

When I use var_dump($site_nid) it shows string(5) "96599". I want to grab the node is which is 96599.

mitchmac’s picture

What happens with var_dump($site_node) ?

agsparta’s picture

Hey, thanks man. I got it. The node loads properly and I was able to use the field values from that external node and show it on the current node.

ludo1960’s picture

Can you show your working code so it helps others?

agsparta’s picture

Sure!

Here is my code:

<?php 
   if($node->type == 'individual' && $node->field_site_node[0]['nid'] != NULL) {
      	
      	// Grab the lat/long coords
      
      	$site_nid = $node->field_site_node[0]['nid'];
      	$site_node = node_load($site_nid);

// You can use the field value from the external node by something like:

$site_node->field_name_field[0]['value']

?>
ludo1960’s picture

Cheers