Home › Forums › Gutenberg › ACF 5.8 – Parse Gutenberg blocks and get ACF data outside of post › Reply To: ACF 5.8 – Parse Gutenberg blocks and get ACF data outside of post
I also ran into this question and solved it with some modifications to the answer given earlier. Maybe it will help someone.
function fetch_large_slider($postId) {
$slider_images = [];
$pid = (empty($postId) ? get_post() : $postId);
// check if acf is used
if (function_exists('get_field')) {
if (has_blocks($pid)) {
$blocks = parse_blocks( $pid->post_content );
// run trough acf gutenberg/acf-blocks and find the right one
foreach ( $blocks as $block ) {
// find all selected images
if ($block["blockName"] == 'acf/full-page-slider') {
// build new array from found images
$image_set = $block["attrs"]["data"]["fullpage_slider_images"];
// collect image urls inside an array
foreach ($image_set as $imageID) {
$slider_images[] = wp_get_attachment_image_src($imageID,'full',false)[0];
}
} else {
continue;
}
}
}
}
return $slider_images;
}
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.