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?

1 Answer 1


Found it! The specific field can be targeted like this:

$criteria->childField = 'myFieldHandle';

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.