Support

Account

Home Forums ACF PRO Field repeater with shortcode better coding

Solved

Field repeater with shortcode better coding

  • Hey everyone, I’m developing a review session. However, I got the way to pull the content layout of the repeater field as in the code below. It works fine. My question is if there is any way to better code the code that I am putting here for your analysis. I’m using shortcode. If you wish to use this function to use your repeater, please feel free to do so.

    function cine_acf_shortcode (  ) {
        
    if ( have_rows( 'criticareview' ) ):
        while ( have_rows( 'criticareview' ) ): the_row();
          $content .= sprintf('<div class="py-1">
        <div class="container-1">
          <div class="row">');
          $content .= sprintf( '
           <div itemscope="" itemtype="http://schema.org/Review" id="review" class="review-cinefilosgamer">
    
          <div class="row">
            <div class="col-md-4">
              <h2 class="display-1 text-secondary">%s</h2></div>', get_sub_field( 'textnotes' ));
          $content .= sprintf( '<div class="col-md-4">
              <h3 class="">%s</h3><p class="lead text-center">%s</p></div>', get_the_title(), get_sub_field('reviewstars') );
    
          $content .= sprintf( '<div class="col-md-4">
              <p class="lead text-center">%s</p>', get_sub_field( 'reviewnumber') );
          $content .= sprintf( '<p class="lead text-center">%s</p>', get_sub_field('reviewquality'));
          $content .= sprintf('<p class="lead text-center">por <a href="%s">%s</a></p>
            </div>
          </div>', get_author_posts_url( get_the_author_meta( 'ID' ), get_the_author_meta( 'user_nicename' ) ), get_sub_field('revnauser'));
           $content .= sprintf('<div class="row">
            <div class="col-md-4"></div>
            <div class="col-md-4"></div>
            <div class="col-md-4"></div>
          </div>
        </div>
    </div>'); 
     
        endwhile;
      endif;
      return $content;
    
    } 
    
     
    add_shortcode( 'acfcine', 'cine_acf_shortcode',1 );
    
Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Field repeater with shortcode better coding’ is closed to new replies.