Support

Account

Home Forums General Issues Change default excerpt to custom post field Reply To: Change default excerpt to custom post field

  • break after the first correct row type, but reset the rows or you may have issues if you need to loop over the rows again

    
    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);
             // break to stop loop
             break;
            endif;
        endwhile;
        else:
        endif;
        reset_rows();
        return $my_acf_field . '' . $excerpt;
    }