Get All Fields from a Field Group Programmatically

Use acf_get_fields() to retrieve all field definitions from a specific field group for dynamic forms, exports, or documentation.

php hooks
|

Use acf_get_fields() to retrieve all field definitions from a specific field group for dynamic forms, exports, or documentation.

Get all fields from a field group by its key:

<?php
$fields = acf_get_fields( 'group_event_details' );

if ( $fields ) {
    foreach ( $fields as $field ) {
        echo $field['label'] . ' (' . $field['type'] . '): ' . $field['name'] . "\n";
    }
}

Each field in the returned array includes the full field configuration — type, label, name, default value, choices, conditional logic, etc.

Build a dynamic summary table of a post’s field values:

<?php
$fields  = acf_get_fields( 'group_event_details' );
$post_id = get_the_ID();

if ( $fields ) : ?>
    <table class="field-summary">
        <thead>
            <tr><th>Field</th><th>Value</th></tr>
        </thead>
        <tbody>
            <?php foreach ( $fields as $field ) :
                $value = get_field( $field['name'], $post_id );
                if ( $value ) : ?>
                    <tr>
                        <td><?php echo esc_html( $field['label'] ); ?></td>
                        <td><?php echo esc_html( is_array( $value ) ? implode( ', ', $value ) : $value ); ?></td>
                    </tr>
                <?php endif;
            endforeach; ?>
        </tbody>
    </table>
<?php endif; ?>

List all field groups and their fields (useful for debugging or documentation):

<?php
$groups = acf_get_field_groups();

foreach ( $groups as $group ) {
    echo '<h3>' . esc_html( $group['title'] ) . '</h3>';

    $fields = acf_get_fields( $group['key'] );
    if ( $fields ) {
        echo '<ul>';
        foreach ( $fields as $field ) {
            echo '<li>' . esc_html( $field['label'] ) . ' — <code>' . esc_html( $field['name'] ) . '</code> (' . esc_html( $field['type'] ) . ')</li>';
        }
        echo '</ul>';
    }
}

Note: acf_get_fields() returns field definitions (configuration), not field values. Use get_fields( $post_id ) to get all values for a specific post.

Related Snippets

Stay Updated

Get ACF tips and new extensions in your inbox

No spam. Unsubscribe anytime.