How do I get the data from a relation field? If use the following code:

$currentEntry = craft()-&gt;entries-&gt;getEntryById($entryId);
$currentContent = $currentEntry-&gt;getContent()-&gt;getAttributes();
$currentAttributes = array();

$fieldLayout = $currentEntry-&gt;getFieldLayout();
foreach ($fieldLayout-&gt;getFields() as $fieldLayoutField) {
    $field = $fieldLayoutField-&gt;getField();
    if (isset($currentContent[$field-&gt;handle])) {
        $currentAttributes[$field-&gt;handle] = $currentContent[$field-&gt;handle];
    }
}


It retrieves all data that I want, but I don't get the data from relation fields. If an asset or entry has been selected, I won't receive that data. The result from that field is always null.

Does anyone know how to do this?
If you already know the custom field name then it is pretty straight forward:

$currentEntry = craft()-&gt;entries-&gt;getEntryById($id);
$relatedEntries = $currentEntry-&gt;customFieldName;


Then you could either loop through each one:

foreach ($relatedEntries as $entry) {
    echo $entry-&gt;title;
}


Or simply get the data from the first one:

echo $relatedEntries-&gt;first()-&gt;title;


Remember that all related entries come back as an array even if you have specified that the user can only select 1.

Hope this helps