Home › Forums › Add-ons › Repeater Field › If repeater field has 1 rows, 2 rows etc › Reply To: If repeater field has 1 rows, 2 rows etc
@neverything, thanks for your post. I used your example to make something for a project I’m working on, but all I needed to do was count number of field and apply different conditions. Here is my stripped down example below:
<?php
// get the count on the repeater field
// mabye use get_sub_field() instead of get_field() if it's nested
$count = count( get_sub_field( 'the_field' ) );
// begin $count conditions
if ( $count > 1 ) { ?>
// greater than 1
<?php the_field( 'great_than_1' ); ?>
<?php } else { ?>
// less than 1
<?php the_field( 'less_than_1' ); ?>
<?php } ?>
https://gist.github.com/emaildano/6b6c47ec2bc3be54fcc6
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.