Why UglyFields
The same page, in code
The best way to see the difference is a small, real job: a team list on an "About" page.
With the usual setup
<?php if ( have_rows( 'team' ) ) : ?>
<ul>
<?php while ( have_rows( 'team' ) ) : the_row(); ?>
<li>
<h3><?php echo esc_html( get_sub_field( 'name' ) ); ?></h3>
<p><?php echo esc_html( get_sub_field( 'role' ) ); ?></p>
</li>
<?php endwhile; ?>
</ul>
<?php endif; ?>There is a hidden "current row". Call a function that also loops, and the cursor is gone. Forget one esc_html() and you have a hole.
With UglyFields
<ul>
<?php foreach ( ugly_rows( 'team' ) as $person ) : ?>
<li>
<h3><?php $person->show( 'name' ); ?></h3>
<p><?php $person->show( 'role' ); ?></p>
</li>
<?php endforeach; ?>
</ul>- No
if:ugly_rows()always gives a list, empty when there is nothing. $personis a variable. Pass it toget_template_part()or to your own function.show()escapes for the type of field.
The functions are listed in Reference: functions.
Did this article answer your question?
Thank you. It helps us make the documentation better. Need more help?