How to integrate Advanced Custom Fields into post text excerpt?

As the title already describes, the following code integrates an ACF field, which of course has to be created beforehand, into the text excerpt of posts.

function testexcerpt() {
    $t_field1 = get_post_meta( get_the_ID(), 'testfeld1', true );
    $t_field2 = get_post_meta( get_the_ID(), 'testfeld2', true );
    $original = get_the_excerpt();
    //Modifies only posts that are displayed on a specific page
    if ( is_page( 12204 ) ) {
  $excerpt = '<div class="new-meta"><img src="beispiel1.png"><br>'. $t_field1 .' </div><div class="new-meta"><img src="beispiel2.png"><br> '.       
        $t_field2 .' </div> ';
    echo $excerpt;
    } else {
    echo $original;
add_filter( 'the_excerpt', 'testexcerpt' );
Without cookies
This website does not use cookies or tracking. More information can be found in the privacy policy.