ACF – get fields from group

Thank you so much for your post, I spent half day to figure out how to get field names by their group.

If you have field names, you can easily get their values: get_field($field[‘name’]);

EXAMPLE HOW TO GET IMAGES FOR SLIDER

    <?php 
                    //or insert the ID of your fields Group.
                    $groupID='116';
                    $custom_field_keys = get_post_custom_keys($groupID);
                    foreach ( $custom_field_keys as $key => $fieldkey )
                    {
                        if (stristr($fieldkey,'field_'))
                        {
                            //echo $key . " => " . $fieldkey . "<br />";
                            //echo $field['label'] . ': ' . $field['value'];
                            //echo $fieldkey . "<br />";
                            $field = get_field_object($fieldkey, $groupID); 

                            $acf_field_name = $field['name'];

                            $attachment = get_field($acf_field_name);
                            echo "<img src="".$attachment["url']."' title="".$attachment["title']."'/>";


                        }
                    }

?> 

Thanks again!

Leave a Comment