2

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?

3

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

$criteria->childField = 'myFieldHandle';
|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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