Home Forums Gutenberg get_field("block_fieldvalue") without ACF


get_field("block_fieldvalue") without ACF

  • I want to get $value = get_field(“block_fieldvalue”) without ACF.

    With multiple custom blocks on a page. If there’s two of the same custom block, I only get the value from the first block. Without the break; — I only get the value from the 2nd block.

    function getACF_block ( $field, $post_id = null) {

    $value = “”;
    $get_post = get_post($post_id);
    $blocks = parse_blocks( $get_post->post_content );

    foreach ( $blocks as $block ) {

    if( isset( $block[‘attrs’][‘data’] ) ) {

    $value = $block[‘attrs’][‘data’][$field];


    return $value;

  • I believe Bill Erickson has some tutorials about retrieving block data. (Pause to look.) Yes! At the bottom of this article, he explains how to use parse_blocks on ACF blocks.

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.

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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.