I'm trying to figure out if it's possible to get an excerpt from each post, grabbing the first paragraph from each one. I'm currently using the ACF plugin and have custom post types and custom fields.
Here's my code:
function custom_field_excerpt() {
global $post;
$text = get_field('news');
if ( '' != $text ) {
$text = strip_shortcodes( $text );
$text = apply_filters('the_content', $text);
$text = str_replace(']]>', ']]>', $text);
$excerpt_length = 20; // 20 words
$text = wp_trim_words( $text, $excerpt_length, $excerpt_more );
}
return apply_filters('the_excerpt', $text);
}
This works great, but it only trims the first 20 words (or however many words you specify), I'm trying to adjust this to pull in the first paragraph of each post instead of the first 20 words. Is this at all possible?