<p>You first need to query for the “airport” entry by using the <code>first()</code> method. <code>$airport-&gt;myEntriedFieldHandle</code> then returns an ElementCriteriaModel prepared to get all the entries selected in the Entries field.</p>

<pre class="lang-php prettyprint-override"><code>$criteria = craft()-&gt;elements-&gt;getCriteria(ElementType::Entry);
$criteria-&gt;section = 'airports';
$criteria-&gt;airportcode = 'BCN';
$airport = $criteria-&gt;first();

if ($airport) {
    $criteria = $airport-&gt;prefHotels;
    $airportPrefHotels = $criteria-&gt;find();

    if ($airportPrefHotels) {
        // do useful things with $airportPrefHotels
    }
}
</code></pre>

CC BY-SA 3.0
2017-05-31T18:51:31.773Z
2017-05-31T18:51:31.773Z
carlcs
<p>I'm trying to bring back a list of entries from a section. Currently I have the following:</p>

<pre><code>$criteria = craft()-&gt;elements-&gt;getCriteria(ElementType::Entry);
$criteria-&gt;section = 'airports';
$criteria-&gt;airportcode = 'BCN';
$airportPrefHotels = craft()-&gt;elements-&gt;findElements($criteria);
</code></pre>

<p>The airport section has a multiple entries field. I want to loop over them.</p>

<p>Is it possible?</p>

CC BY-SA 3.0
2017-05-31T17:58:08.210Z
What type of field is `airportcode`? Also, you tagged this with `craft3`, but I assume you're referring to Craft 2 here, correct?
Brad Bell
CC BY-SA 3.0
2017-05-31T18:01:41.610Z
It wouldn't let me add craft 2.

airportCode is a text field inside the section.

I want to access the entries inside the field attached to the airport section
Christophfen
CC BY-SA 3.0
2017-05-31T18:24:45.947Z
So inside of an entry inside of a section with a handle of `airports`, you've got an [entries field] for relating other entries. What's the name of that field? And do you want to loop over all of those related entries for every parent entry?
Brad Bell
CC BY-SA 3.0
2017-05-31T18:54:26.233Z
I’m assuming there only one airport matching that criteria? If that’s right see my answer below @Christophfen
carlcs
<entries><elementcriteriamodel>
Entries inside controller
# Entries inside controller

(Asked by: username_0 on 2017-05-31)

I'm trying to bring back a list of entries from a section. Currently I have the following:
$criteria = craft()->elements->getCriteria(ElementType::Entry);
$criteria->section = 'airports';
$criteria->airportcode = 'BCN';
$airportPrefHotels = craft()->elements->findElements($criteria);

The airport section has a multiple entries field. I want to loop over them.
Is it possible?

**Tags:** entries, elementcriteriamodel
> **Comments:**
> **username_1**: What type of field is `airportcode`? Also, you tagged this with `craft3`, but I assume you're referring to Craft 2 here, correct?  
> **username_0**: It wouldn't let me add craft 2.  airportCode is a text field inside the section.  I want to access the entries inside the field attached to the airport section  
> **username_1**: So inside of an entry inside of a section with a handle of `airports`, you've got an [entries field] for relating other entries. What's the name of that field? And do you want to loop over all of those related entries for every parent entry?  
> **username_2**: I’m assuming there only one airport matching that criteria? If that’s right see my answer below @Christophfen  

---

## 1 answers

### Answer by username_2 on 2017-05-31. Score: 1 | Accepted answer

You first need to query for the “airport” entry by using the first() method. $airport->myEntriedFieldHandle then returns an ElementCriteriaModel prepared to get all the entries selected in the Entries field.
$criteria = craft()->elements->getCriteria(ElementType::Entry);
$criteria->section = 'airports';
$criteria->airportcode = 'BCN';
$airport = $criteria->first();

if ($airport) {
    $criteria = $airport->prefHotels;
    $airportPrefHotels = $criteria->find();

    if ($airportPrefHotels) {
        // do useful things with $airportPrefHotels
    }
}


---

