Skip to content
Custom fields for WordPress that are quick to build and quick to load. Get Pro
Docs

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.

1 minute to read Updated 1 week ago

With the usual setup

PHP
<?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

PHP
<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.
  • $person is a variable. Pass it to get_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?