Two different ways to query entities / nodes: entityQuery and entityTypeManager
$results = \Drupal::entityQuery('app_voucher') ->range(0, 20000) ->execute(); foreach ($results as $result) { $messenger = \Drupal::messenger(); $voucher_entity = \Drupal::entityTypeManager()->getStorage("app_voucher")->load($result); $voucher_id = $voucher_entity->voucher_id->getValue(); $product_id = $voucher_entity->product_id->getValue(); }
Here are 2 different ways to get the same sort of data: