php – ACF: how do I get the fields and its values of a specific group?


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

<?php if( $fields )
foreach( $fields as $field)
    $value = get_field( $field['name'] );

    if ($value) {
        echo '<dl>';
            echo '<dt>' . $field['label'] . '</dt>';
            echo '<dd>' . $field['value'] . '</dd>';
        echo '</dl>';


This is what I have. If I do a var_dump on acf_get_fields, it apparently sets the value to NULL. I could have known, as it’s written here:

The problem: I have to first get all fields in a specific field_group, hence I am using acf_get_fields.

I thought with using $field['value'] I could get it to work, but apparently this does not work.

Can someone help me to retrieve the values in the foreach per field? Surely there must be a way?



$fields = get_fields();

if( $fields ): ?>
        <?php foreach( $fields as $name => $value ): ?>
            <li><b><?php echo $name; ?></b> <?php echo $value; ?></li>
        <?php endforeach; ?>
<?php endif; ?>

This gives me ALL fields. I just need a specific list of fields from a specific field group. That is the problem.

I tried all suggestions here: ACF – get fields from group, but none of them do the trick for my case.

johan 10 months 2021-10-01T12:20:07-05:00 0 Answers 0 views 0

Leave an answer