## Issue using ACF Flexible Content Sub Field for Excerpt

Question

I’m developing a site where the blog entries will be made using ACF Pro / Flexible Content Fields. Because the post entry content will no longer be entered into the default content editor, WP is unable to pull an excerpt. I patched together some code from searches earlier today and was able to finally get an excerpt working but it’s now only pulling from the last blog_post_text sub field instead of the first if more than one is entered. In each post, the user can add several instances of each sub-field based on how many text or image blocks the post needs. I’d like to pull the excerpt from the first blog_post_text sub field used (which is usually the intro paragraph to the post).

I’m sure there are better ways to write this but I’ve tried many and this is the one that worked. Any help or guidance would be incredibly appreciated. Just started using ACF recently.

add_filter('the_excerpt', 'your_function_name');

function your_function_name($excerpt) { if( have_rows('blog_post_content') ): while ( have_rows('blog_post_content') ) : the_row(); if( get_row_layout() == 'blog_post_text_content' ):$my_acf_field = wp_trim_words(get_sub_field('blog_post_text'), 100);

endif;
endwhile;
else:
endif;
return \$my_acf_field;
}


0
1 year 2020-07-11T18:10:22-05:00 0 Answers 78 views 0