Support

Account

Home Forums Gutenberg Displaying Gutenberg block from archive page Reply To: Displaying Gutenberg block from archive page

  • If anyone is interested I found a solution to this in another thread – https://support.advancedcustomfields.com/forums/topic/acf-5-8-parse-gutenberg-blocks-and-get-acf-data-outside-of-post/

    <?php if (have_posts()) :
      while (have_posts()) : the_post();?>
        <?php if ( function_exists( 'get_field' ) ) {
          $pid = get_post();
          if ( has_blocks( $pid ) ) {
            $blocks = parse_blocks( $pid->post_content );
            foreach ( $blocks as $block ) {
              if ( $block['blockName'] === 'acf/your-acf-block' ) {
                $field = $block['attrs']['data']['your_acf_field'];
              } 
            }
          }
        } ?>
        <?php echo $field; ?>
      <?php endwhile; ?>
    <?php endif; ?>