<p>Found it! The specific field can be targeted like this:</p>

<pre><code>$criteria-&gt;childField = 'myFieldHandle';
</code></pre>

CC BY-SA 3.0
2014-08-22T00:04:36.950Z
2014-08-22T00:04:36.950Z
Lindsey D
<p>I'm trying to grab an Asset which is a child of my Entry...</p>

<pre class="lang-php prettyprint-override"><code>$criteria = craft()-&gt;elements-&gt;getCriteria(ElementType::Asset);
$criteria-&gt;childOf = $entryId;
$photo = craft()-&gt;assets-&gt;findFile($criteria);
</code></pre>

<p>For the most part, this works pretty well. But my entry has multiple Asset fields, and <strong>sometimes it grabs the wrong image</strong>.</p>

<p>I suspect that I just need to add another parameter to my <code>$criteria</code>, but I can't figure out what... theoretically something to denote which specific field I'm referring to. Any suggestions?</p>

<plugin-development><elementcriteriamodel><assetfilemodel>
How can I get a related Asset of a specific field?
# How can I get a related Asset of a specific field?

(Asked by: username_0 on 2014-08-21)

I'm trying to grab an Asset which is a child of my Entry...
$criteria = craft()->elements->getCriteria(ElementType::Asset);
$criteria->childOf = $entryId;
$photo = craft()->assets->findFile($criteria);

For the most part, this works pretty well. But my entry has multiple Asset fields, and sometimes it grabs the wrong image.
I suspect that I just need to add another parameter to my $criteria, but I can't figure out what... theoretically something to denote which specific field I'm referring to. Any suggestions?

**Tags:** plugin-development, elementcriteriamodel, assetfilemodel


---

## 1 answers

### Answer by username_0 on 2014-08-22. Score: 3 | Accepted answer

Found it! The specific field can be targeted like this:
$criteria->childField = 'myFieldHandle';


---

