'PHP code for ACF inside Wordpress add_filter

I have a code snippet for inserting information at a specific point on my Wordpress website:

add_filter(
'hivepress/v1/templates/vendor_view_page/blocks',
function( $blocks, $template ) {
    return hivepress()->helper->merge_trees(
            [ 'blocks' => $blocks ],
            [
                'blocks' => [
                    'page_content' => [
                        'blocks' => [
                            'custom_listings_text' => [
                                    'type'    => 'content',
                                    'content' => 'Your content here',
                                    '_order'  => 1,
                            ],
                        ],
                    ],
                ],
            ]
        )['blocks'];
},
1000,
2
);

I want to change the 'Your content here' with information from an Advanced Custom Field. I know, that the regular way to get the information is with this code:

<?php if( get_field('text_field') ): ?>
<h2><?php the_field('text_field'); ?></h2>
<?php endif; ?>

How can I get the 'text_field' as a variable into the snippet, so it shows the ACF? I tried to exchange „Your content here“ with every form of the ACF Code but either my site crashes or I just get plain text or the php-code is presented as a comment in the result.



Solution 1:[1]

Per the ACF documentation you need to include the ID of the page or post it is coming from. - https://www.advancedcustomfields.com/resources/get_field/

This allows you to use it anywhere and pull data basically from anything.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Bazdin