Search code examples
drupal-7

Hey can someone help by loading a node with node_load()


I check if a specific content exists with

// Check If node already exists
   $nodeexist = db_select('field_data_field_id', 'r')
     ->fields ('r', array('field_id_value'))
     ->condition ('field_id_value', $row->id, '=')
     ->execute()
     ->fetchAssoc();

If it doesn´t exist I create new content, but if it exist how can i load it, to change some parameters, will be thankfull for help


Solution

  • If field is attached to Node , you can find nid with 'entity_id' column , like this :

    $nid = db_select('field_data_field_id', 'r')
         ->fields ('r', array('entity_id'))
         ->condition ('field_id_value', $row->id, '=')
         ->condition ('entity_type', 'node', '=')
         ->execute()
         ->fetchField();
    if(!empty($nid)){
      $node = node_load($nid);
    }else{
       // TODO: create new node 
    }