How to Limit Word Count for a CPT With an ACF Field Excerpt

This example was used when creating a custom Gutenberg block for displaying a single, specific post from a CPT that’s built with ACF.

function custom_field_excerpt() {
    $custom_field = get_field( 'custom_field' );
    $excerpt = get_field( 'custom_field_excerpt', $custom_field );
    $excerpt_length = 20;
    $trim = wp_trim_words( $excerpt, $excerpt_length );
    return apply_filters( $excerpt, $trim );
}

echo custom_field_excerpt();