1

I am trying to load all media items of a certain type but I can't find how to.

Is there a way to set a filtering type on something like

$media = Media::loadMultiple();

Or do you have to load all media and then filter manually?

1
  • How about using views? Commented Jul 30, 2019 at 14:58

1 Answer 1

5

If you use entity query you can filter the entities by type before uploading them.

$ids = \Drupal::entityQuery('media')
  ->condition('bundle', 'YOUR_TYPE')
  ->execute();

$medias = Media::loadMultiple($ids);
1
  • You may need to add use Drupal\media\Entity\Media;
    – pmagunia
    Commented Nov 3, 2022 at 11:40

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.