Retrieve or echo a sub-field value inside a have_rows() loop. These functions only work within the context of a while ( have_rows() ) : the_row(); loop.
get_sub_field( $selector )
Parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
$selector | string | — | Sub-field name |
mixed — the sub-field value.
the_sub_field( $selector )
Parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
$selector | string | — | Sub-field name |
void (outputs directly).
php
if ( have_rows( 'features' ) ) :
echo '<ul>';
while ( have_rows( 'features' ) ) : the_row();
echo '<li>';
echo '<strong>' . esc_html( get_sub_field( 'title' ) ) . '</strong>: ';
the_sub_field( 'description' );
echo '</li>';
endwhile;
echo '</ul>';
endif;get_sub_field_object( $selector )
Get the full field definition of a sub-field inside a row loop.
Parameters:| Parameter | Type | Default | Description |
|---|---|---|---|
$selector | string | — | Sub-field name |
array|false — field definition array with value, or false if not found.
php
if ( have_rows( 'settings' ) ) :
while ( have_rows( 'settings' ) ) : the_row();
$obj = get_sub_field_object( 'color_scheme' );
// $obj = ['name' => 'color_scheme', 'type' => 'select', 'choices' => [...], 'value' => 'dark']
echo '<p>Current: ' . esc_html( $obj['value'] ) . '</p>';
echo '<p>Choices: ' . implode( ', ', $obj['choices'] ) . '</p>';
endwhile;
endif;—