Devar-TTY
Devar-TTY

Reputation: 476

How do I query Drupal 8 Media by type?

I've created a Media type called "ad_gallery" can I can't seem to pull in all the entries while preprocessing.

I'm trying

\Drupal::entityQuery('media')->condition('type','ad_gallery')->execute();

And it's saying:

Drupal\Core\Entity\Query\QueryException: 'type' not found in Drupal\Core\Entity\Query\Sql\Tables->ensureEntityTable()

Is there a different way to query these than there is nodes?

Upvotes: 3

Views: 2194

Answers (1)

anpel
anpel

Reputation: 941

You should use bundle instead of type.

Something like this will do the trick:

\Drupal::entityQuery('media')->condition('bundle', 'ad_gallery')->execute();

Upvotes: 4

Related Questions