How to load custom block via code? I created a new custom block type from /admin/structure/block/block-content/types  having  x and y fields with field types image and textfield respectively.  Then created a block with the same block type  and uploaded image in x and some text in y.  Here  my problem is: how to load this block via code?

More than that how to get values of these block fields x and y  by loading the block?

I tried these:

$block = \Drupal\block_content\Entity\BlockContent::load($bid);
$render = \Drupal::entityManager()-&gt;getViewBuilder('block_content')-&gt;view($block);


but it didn't work.
Place the block in the disabled section at admin/structure/block, this creates a block instance with your block_content type, give it a nice easy machine name to remember.  



By placing it in the disabled section, it won't show up, until you load it programatically.

Then using your machine name:

$machine_name = 'myblock';

$block = \Drupal::entityTypeManager()
  -&gt;getStorage('block')
  -&gt;load($machine_name);
if (!empty($block)) {
  $block_content = \Drupal::entityTypeManager()
    -&gt;getViewBuilder('block')
    -&gt;view($block);

  $pre_render = $block_content;
}


If you really want to get the rendered fields, you can do:

$render = \Drupal::entityTypeManager()
  -&gt;getViewBuilder('block')
  -&gt;build($pre_render);


But it is more standard practice to use Drupal's formatters and such and perhaps a custom template, rather than building the block and extracting elements from the rendered render array.