Support

Account

Home Forums ACF PRO First 3 of relationship field Reply To: First 3 of relationship field

  • I used a counter to solve this. Found a solution for the gallery field that worked the same way.

    Here you go!

    
    <?php 
    $posts = get_field('books');
    $max = 3;
    $i = 0;              
    if( $posts ): ?>
    <?php foreach( $posts as $post): $i++; ?>
    <?php if( $i > $max){ break; } ?>
      <?php setup_postdata($post); ?>
      <div class="col-xs-6 col-sm-3">
        <a href="<?php the_permalink(); ?>">
        <?php if (has_post_thumbnail( $post->ID ) ): ?>
          <?php $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'book-thumbnail' ); ?>
          <img class="img-responsive" src="<?php echo $image[0]; ?>" alt="<?php the_title(); ?>">
        <?php endif; ?>
        </a>
      </div>
    <?php endforeach; ?>
    <?php endif; ?>