How to determine the number of entries in a field
-
I’m sorry, I cannot think of a way to word this in a search to find what I want, and I am fairly remedial at php so this might be super basic knowledge. Basically, I’m looking to use the following to pull up an unordered list of results:
<?php if(get_field('prevention')): ?> <ul> <?php while(has_sub_field('prevention')): ?> <li><?php the_sub_field('prevention_method'); ?></li> <?php endwhile; ?> </ul> <?php endif; ?>
But I need to alter it so that if the sub_field(‘prevention’) only has 1 result, to just display:
<?php the_sub_field('prevention_method'); ?>
with no unordered list around it. There will always be at least 1 result because it is a required field. Is there a way to make this happen? I did not write this code, it was given to me this way so I would prefer to keep it as close to the intended format as possible!
Viewing 5 replies - 1 through 5 (of 5 total)
Viewing 5 replies - 1 through 5 (of 5 total)
- The topic ‘How to determine the number of entries in a field’ is closed to new replies.