This is a single asset field to upload multiple images so how to get all images using the query. enter image description here

I have three images here but I am getting one image using this code

$home = \craft\elements\Entry::find()
  foreach ($home->infographics as $key => $infographicsValue) {
        $infographicsImage[$key]['image'] = $infographicsValue->infographicsImage;



Please help me to solve this issue. Thank you!!

  • Can you add more of your code? The output looks like you are using Element API.
    – Oli
    Commented Nov 16, 2021 at 6:53

2 Answers 2


Edit: Previous answer was incorrect, see update below.

What kind of field is infographics? How is it related to the infographicsImage field you're accessing in the loop?

Either way, one of those is the assets field. Accessing an Assets field by handle returns an AssetQuery, not an Asset itself. To access the resulting assets, you need to execute the query using ->one() or ->all(), which will give you either a single Asset object (or null) or an array of Asset objects (which may be empty).

Please provide more info regarding the fields.

  • I can't find the field 'infographics' of a particular section using the craft\elements\Asset Commented Nov 16, 2021 at 5:21
  • @SantanuAdak My answer was incorrect, I've misread the code in your question. Either way, you're not executing the asset query correctly, see my updated answer. If you provide more information, I can provide a more detailed answer.
    – MoritzLost
    Commented Nov 16, 2021 at 10:18

I have fixed this issue with this code

foreach ($home->infographics as $key => $infographicsValue) {
     $imageArr['width'] = $infographicsValue['width'] ? $infographicsValue['width'] : "";
     $imageArr['height'] = $infographicsValue['height'] ? $infographicsValue['height'] : "";
     $imageArr['alt'] = $infographicsValue['title'] ? $infographicsValue['title'] : "";
     $imageArr['url'] = $infographicsValue['url'] ? $infographicsValue['url'] : "";
     $infographicsImage[$key]['image'] = $imageArr;

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.