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; ?>
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.