Drupal 8: entityQuery and render custom blocks by bundle
In below example, 'testimonial' is our custom block type (bundle) which we added in /admin/structure/block/block-content/types. Drupal 8 default install sets you up with one type called 'basic'.
$html = '';
$query = \Drupal::entityQuery('block_content')
->condition('type', 'testimonial');
$ids = $query->execute();
$blocks = entity_load_multiple('block_content', $ids);
$view_mode = 'default';
foreach ($blocks as $entity) {
$html .= render(entity_view($entity, $view_mode));
}
return $html;
Note: the entity type is 'block_content', and NOT 'block'. The latter will return active blocks for all active themes or something like that.
Links:
https://www.drupal.org/node/1827278
http://www.sitepoint.com/drupal-8-version-entityfieldquery