Skip to content

Instantly share code, notes, and snippets.

@aibrean
Forked from emaildano/acf-field-counter.php
Created March 11, 2016 17:06
Show Gist options
  • Save aibrean/25056a8a41cb5d1ac9b0 to your computer and use it in GitHub Desktop.
Save aibrean/25056a8a41cb5d1ac9b0 to your computer and use it in GitHub Desktop.
ACF field counter snippet.
<?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 } ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment