SHARE
TWEET

Untitled

a guest Jan 24th, 2019 61 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function advanced_custom_field_excerpt() {
  2.     global $post;
  3.  
  4. // check if the flexible content field has rows of data
  5. if( have_rows('post_flexible_content') ):
  6.  
  7.      // loop through the rows of data
  8.     while ( have_rows('post_flexible_content') ) : the_row();
  9.  
  10.     $text = get_sub_field('flexible_text_editor');
  11.     if ( '' != $text ) {
  12.         $text = strip_shortcodes( $text );
  13.         $text = apply_filters('the_content', $text);
  14.         $text = str_replace(']]>', ']]>', $text);
  15.         $excerpt_length =30; // 30 words
  16.         $excerpt_more = apply_filters('excerpt_more', ' ' . '[...]');
  17.         $text = wp_trim_words( $text, $excerpt_length, $excerpt_more );
  18.         break;
  19.     }
  20.  
  21.     endwhile;
  22.  
  23. else :
  24.  
  25.     // no layouts found
  26.  
  27. endif;
  28.  
  29.     return apply_filters('the_excerpt', $text);
  30. }
  31. add_shortcode("flexible-excerpt", "advanced_custom_field_excerpt");
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top