6. have_rows() and the_row() | Field Forge - Custom Fields, Built for Speed
Download Log in

6. have_rows() and the_row()

Developer Guide

Used with Repeater, Group, and Flexible Content fields to iterate through structured data.

have_rows( $selector, $post_id ) / the_row()

Parameters:
ParameterTypeDefaultDescription
$selectorstringRepeater, group, or flexible content field name
$post_idintstringfalsefalsePost ID, 'options', or false for current post
Returns: booltrue 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;

Forge AI Assistant Online

Hi! I'm the Field Forge AI assistant. Ask me anything about the plugin — setup, features, troubleshooting, or development.

Just now
Powered by Forge AI · Browse docs