<p>This is the same as using <code>craft.entries</code> in Twig. To get the entries from a <code>ElementCriteriaModel</code> you need to call the <code>find()</code> method. </p>

<p>In a plugin you can do this like this:</p>

<pre><code>$relatedEntries = $center-&gt;hotline-&gt;find();
</code></pre>

<p>The variable <code>$relatedEntries</code> will be an array of <code>EntryModel</code>s if multiple entries are related in the field or a single <code>EntryModel</code> if there is a single entry related in the field. </p>

CC BY-SA 3.0
2017-09-22T16:29:24.067Z
2017-09-22T16:29:24.067Z
Steve Rowling
<p>Nevermind.</p>

<p>Apparently I have to grab <code>first()</code> which will give me the selected entry.</p>

<p>I know I tried this before and it didn't work. I must have been in the wrong context or something.</p>

<p><code>$center-&gt;getFieldValue('hotline')-&gt;first();</code>
or
<code>$center-&gt;hotline-&gt;first();</code> is what I needed.</p>

CC BY-SA 3.0
2017-09-22T16:23:23.217Z
2017-09-22T16:23:23.217Z
Rick Kukiela
<p>So I have some entries and one of the fields is for a "hotline". The hotlines are all entries. The CMS part works, I can click the field and choose an entry from the hotlines channel, however this is where I'm stuck.</p>

<p>In my plugin code I cannot seem to figure out a way to actually get the hotline that was chosen. </p>

<p>I have a <code>$center</code> variable which is an <code>EntryModel</code> of the entry that has the field for "hotlines" attached to it, with the value set (according to the admin).</p>

<p><code>$center-&gt;hotline</code> and <code>$center-&gt;getFieldValue('hotline')</code> just return an <code>ElementCriteriaModel</code> and when I inspect that object inside xdebug there is nothing there that would be usable in getting the actual hotline that's selected. No ID. No object. No nothing. Just information about the field it self, not the value.</p>

<p>What the heck am I doing wrong here? This is so "unintuitive" compared to the rest of craft! </p>

<plugin-development>
Entry FieldType - Get the EntryModel of the entry chosen in the field?
# Entry FieldType - Get the EntryModel of the entry chosen in the field?

(Asked by: username_0 on 2017-09-22)

So I have some entries and one of the fields is for a "hotline". The hotlines are all entries. The CMS part works, I can click the field and choose an entry from the hotlines channel, however this is where I'm stuck.

In my plugin code I cannot seem to figure out a way to actually get the hotline that was chosen.

I have a `$center` variable which is an `EntryModel` of the entry that has the field for "hotlines" attached to it, with the value set (according to the admin).

`$center->hotline` and `$center->getFieldValue('hotline')` just return an `ElementCriteriaModel` and when I inspect that object inside xdebug there is nothing there that would be usable in getting the actual hotline that's selected. No ID. No object. No nothing. Just information about the field it self, not the value.

What the heck am I doing wrong here? This is so "unintuitive" compared to the rest of craft!

**Tags:** plugin-development

---

## 2 answers

### Answer by username_1 on 2017-09-22. Score: 1 | Accepted answer

This is the same as using craft.entries in Twig. To get the entries from a ElementCriteriaModel you need to call the find() method. 
In a plugin you can do this like this:
$relatedEntries = $center->hotline->find();

The variable $relatedEntries will be an array of EntryModels if multiple entries are related in the field or a single EntryModel if there is a single entry related in the field.


---

### Answer by username_0 on 2017-09-22. Score: 1

Nevermind.

Apparently I have to grab `first()` which will give me the selected entry.

I know I tried this before and it didn't work. I must have been in the wrong context or something.

`$center->getFieldValue('hotline')->first();`
or
`$center->hotline->first();` is what I needed.


---

