Get content block by post ID
-
Hello,
I am trying to retrieve the content of a block via its ID.
I tried something like this<?php $post_id = 234; $post = get_post($post_id); $blocks = parse_blocks($post->post_content); print'<pre>';print_r($blocks);print'</pre>'; foreach ($blocks as $block) { if ($block['image_header'] == 'lazyblock/client-header') { render_block($block); } } ?>Array ( [0] => Array ( [blockName] => lazyblock/client-header [attrs] => Array ( [titre] => Lorem ipsum [header_image] => %7B%22alt%22:%22Gulf-Air%22,%22title%22:%22Gulf-Air%22,%22caption%22:%22%22,%22description%22:%22%22,%22id%22:359,%22link%22:%22//192.168.1.35:3000/fr/client/amiri-flight/gulf-air-5/%22,%22url%22:%22//192.168.1.35:3000/wp-content/uploads/2021/02/Gulf-Air-5-scaled.jpg%22,%22sizes%22:%7B%22thumbnail%22:%7B%22height%22:150,%22width%22:150,%22url%22:%22//192.168.1.35:3000/wp-content/uploads/2021/02/Gulf-Air-5-150x150.jpg%22,%22orientation%22:%22landscape%22%7D,%22medium%22:%7B%22height%22:300,%22width%22:200,%22url%22:%22//192.168.1.35:3000/wp-content/uploads/2021/02/Gulf-Air-5-200x300.jpg%22,%22orientation%22:%22portrait%22%7D,%22large%22:%7B%22height%22:960,%22width%22:640,%22url%22:%22//192.168.1.35:3000/wp-content/uploads/2021/02/Gulf-Air-5-683x1024.jpg%22,%22orientation%22:%22portrait%22%7D,%22full%22:%7B%22url%22:%22//192.168.1.35:3000/wp-content/uploads/2021/02/Gulf-Air-5-scaled.jpg%22,%22height%22:2560,%22width%22:1707,%22orientation%22:%22portrait%22%7D%7D%7D [soustitre] => Lorem ipsum dolor [blockId] => Z2gkChz [blockUniqueClass] => lazyblock-client-header-Z2gkChz ) [innerBlocks] => Array ( ) [innerHTML] => [innerContent] => Array ( ) )How to get the URL of header_image ?
The topic ‘Get content block by post ID’ is closed to new replies.