Skip to content

Repeater

A repeatable row field that lets users add, remove, and reorder groups of sub-fields.

Repeater Field

The Repeater field creates a dynamic list of rows, where each row contains a defined set of sub-fields. Users can add as many rows as needed and reorder them by dragging. Use it for team members, portfolio items, FAQs, pricing tiers, or any repeating content structure.

For a complete guide including advanced usage, see the dedicated Repeater Fields documentation.


Field Settings

SettingDescription
Field KeyUnique identifier. Lowercase letters and underscores only.
LabelDisplay label shown above the repeater.
DescriptionOptional helper text.
Button TextLabel for the “Add Row” button (default: Add Row).
Sub FieldsThe fields that appear inside each row. Any field type can be used as a sub-field.

Return Value

Returns an array of associative arrays — one per row. Each row array is keyed by sub-field key.

php

// Example return value for a repeater with 'name' and 'role' sub-fields
[
    [ 'name' => 'Faruk Ahmed', 'role' => 'Lead Developer' ],
    [ 'name' => 'Jane Smith',  'role' => 'Designer' ],
]

Returns an empty array [] if no rows have been added.


Usage

php

// Get the repeater rows (returns array of arrays)
$team = onemeta_get_meta( get_the_ID(), 'field_key' );

if ( is_array( $team ) && ! empty( $team ) ) {
    foreach ( $team as $member ) {
        $name   = $member['member_name']   ?? '';
        $role   = $member['member_role']   ?? '';
        $avatar = $member['member_avatar'] ?? '';

        echo '<div class="team-member">';

        if ( ! empty( $avatar ) ) {
            echo wp_get_attachment_image( $avatar, 'thumbnail', false, [
                'alt' => esc_attr( $name ),
            ] );
        }

        echo '<h3>' . esc_html( $name ) . '</h3>';
        echo '<p>'  . esc_html( $role ) . '</p>';
        echo '</div>';
    }
}

Template Example

php

<?php $faqs = onemeta_get_meta( get_the_ID(), 'faqs' ); ?>

<?php if ( is_array( $faqs ) && ! empty( $faqs ) ) : ?>
    <div class="faq-list">
        <?php foreach ( $faqs as $faq ) : ?>
            <details class="faq-item">
                <summary class="faq-question">
                    <?php echo esc_html( $faq['question'] ?? '' ); ?>
                </summary>
                <div class="faq-answer">
                    <?php echo wp_kses_post( wpautop( $faq['answer'] ?? '' ) ); ?>
                </div>
            </details>
        <?php endforeach; ?>
    </div>
<?php endif; ?>

Notes

  • Always use is_array() before looping — the value may be empty
  • Access sub-field values using the sub-field key with a null coalescing default: $row['key'] ?? ''
  • Sub-fields support all 13 other field types including Image, Toggle, Select, and nested text fields
  • For a full guide on setting up sub-fields and advanced repeater patterns, see Repeater Fields

On This Page