Used with Repeater, Group, and Flexible Content fields to iterate through structured data.
have_rows( $selector, $post_id ) / the_row()
Parameters:
| Parameter | Type | Default | Description | ||
|---|---|---|---|---|---|
$selector | string | — | Repeater, group, or flexible content field name | ||
$post_id | int | string | false | false | Post ID, 'options', or false for current post |
bool — true if rows exist and there are more rows to iterate.
php
// Basic repeater loop
if ( have_rows( 'team_members' ) ) :
while ( have_rows( 'team_members' ) ) : the_row();
$name = get_sub_field( 'name' );
$photo = get_sub_field( 'photo' );
echo '<div class="team-member">';
echo '<h3>' . esc_html( $name ) . '</h3>';
if ( $photo ) {
echo '<img src="' . esc_url( $photo ) . '" alt="">';
}
echo '</div>';
endwhile;
endif;
// Repeater from a specific post
if ( have_rows( 'pricing_tiers', 99 ) ) :
while ( have_rows( 'pricing_tiers', 99 ) ) : the_row();
echo '<div class="tier">';
echo '<h3>' . esc_html( get_sub_field( 'plan_name' ) ) . '</h3>';
echo '<p class="price">$' . esc_html( get_sub_field( 'price' ) ) . '/mo</p>';
echo '</div>';
endwhile;
endif;
// Repeater from options page
if ( have_rows( 'announcement_bar', 'options' ) ) :
while ( have_rows( 'announcement_bar', 'options' ) ) : the_row();
echo '<div class="announcement">' . esc_html( get_sub_field( 'message' ) ) . '</div>';
endwhile;
endif;—