How to get saved images

I'm saving an entity object of type entity and subtype album. When saving the album, I also save it with image files who's $ownerGUID = $album-> GUID. They get uploaded OK. The problem I'm now having is when it comes to retrieving the images. How can I go about listing all the images that belong to a particular album?

Thank you all in advance.

Elgg 2.X

  • There is no such type as 'entity', only 'object', 'user', 'group' and 'site'. By design entity owners should be user entities (there are rare exceptions, but you want to avoid that). Set your image's container_guid to album's guid, and use elgg_get_entities().

    $image = new ElggObject();
    $image->subtype = 'image';
    $image->container_guid = $album->guid;
    $image->access_id = ACCESS_PUBLIC;
    $image->save();
    
    elgg_get_entities([
       'types' => 'object',
       'subtypes' => 'image',
       'container_guids' => $album->guid,
    ]);
    
  • Thank you for the reply @Ismayil Khayredinov. How do I then loop through and display the images? I don't think I can use something like $description = $image -> description; here

  • $images = elgg_get_entities([
       'types' => 'object',
       'subtypes' => 'image',
       'container_guids' => $album->guid,
    ]);
    
    foreach ($images as $image) {
       echo $image->description;
    }
    
Beginning Developers

Beginning Developers

This space is for newcomers, who wish to build a new plugin or to customize an existing one to their liking