Skip to main content
deleted 22 characters in body
Source Link
mchar
  • 1.7k
  • 1
  • 11
  • 20

Like this, you will get all the referenced items of the node being displayed.

  $current_path = explode('/', $_GET['q']);
  if ($current_path[0] == 'node' && is_numeric($nid = $current_path[1])) {
    $field = 'my_field';
    $bundle = 'my_bundle';
    $query = db_query("SELECT {$field}_target_id FROM node, field_data_{$field} WHERE nid = entity_id AND entity_id = :nid AND bundle = :bundle",
      array(
        ':nid' => $nid,
        ':bundle' => $bundle,
      )
    );
    foreach($query as $row) {
      $target_ids[] = $row->{$field . "_target_id"};
    }
    $nodes = node_load_multiple($target_ids);
  }

If you have more entity reference fields, you have to expand the query (with more joins) according to your fields.

Like this, you will get all the referenced items of the node being displayed.

  $current_path = explode('/', $_GET['q']);
  if ($current_path[0] == 'node' && is_numeric($nid = $current_path[1])) {
    $field = 'my_field';
    $bundle = 'my_bundle';
    $query = db_query("SELECT {$field}_target_id FROM node, field_data_{$field} WHERE nid = entity_id AND entity_id = :nid AND bundle = :bundle",
      array(
      ':nid' => $nid,
      ':bundle' => $bundle,
      )
    );
    foreach($query as $row) {
      $target_ids[] = $row->{$field . "_target_id"};
    }
    $nodes = node_load_multiple($target_ids);
  }

If you have more entity reference fields, you have to expand the query (with more joins) according to your fields.

Like this, you will get all the referenced items of the node being displayed.

  $current_path = explode('/', $_GET['q']);
  if ($current_path[0] == 'node' && is_numeric($nid = $current_path[1])) {
    $field = 'my_field';
    $bundle = 'my_bundle';
    $query = db_query("SELECT {$field}_target_id FROM field_data_{$field} WHERE entity_id = :nid AND bundle = :bundle",
      array(
        ':nid' => $nid,
        ':bundle' => $bundle,
      )
    );
    foreach($query as $row) {
      $target_ids[] = $row->{$field . "_target_id"};
    }
    $nodes = node_load_multiple($target_ids);
  }

If you have more entity reference fields, you have to expand the query (with more joins) according to your fields.

Source Link
mchar
  • 1.7k
  • 1
  • 11
  • 20

Like this, you will get all the referenced items of the node being displayed.

  $current_path = explode('/', $_GET['q']);
  if ($current_path[0] == 'node' && is_numeric($nid = $current_path[1])) {
    $field = 'my_field';
    $bundle = 'my_bundle';
    $query = db_query("SELECT {$field}_target_id FROM node, field_data_{$field} WHERE nid = entity_id AND entity_id = :nid AND bundle = :bundle",
      array(
      ':nid' => $nid,
      ':bundle' => $bundle,
      )
    );
    foreach($query as $row) {
      $target_ids[] = $row->{$field . "_target_id"};
    }
    $nodes = node_load_multiple($target_ids);
  }

If you have more entity reference fields, you have to expand the query (with more joins) according to your fields.