Home › Forums › Front-end Issues › Absolute display of all fields
Hi,
I’m trying to create a code that could display all fields, in an absolute way, without knowing the fields’names.
But I’m stuck with my code when trying to get fields from a repeater field. From what I get, there’s no label at all for the fields inside a repeater. But it makes no sense. There should be.
Here’s my attempt :
$fields = get_field_objects();
if( $fields ):
echo '<div class="fields-container">';
foreach( $fields as $name => $field ):
$champ = get_field_object($name); // get the object by name
echo '<div class="' . $champ['name'] . '-label field-label">' . $champ['label'] . '</div>';
// if repeater
if( $champ['type'] == 'repeater' ) {
$rows = get_field_object($champ['name']);
// here want an object with each row of the repeater to get the labels
// other fields
} else {
echo '<div class="' . $champ['name'] . '-value field-value">' . $champ['value'] . '</div>';
}
endforeach;
echo '</div>';
endif;
I tried many things but never get the right object.
Thanks a lot for any help.
Hi @vguenichon
Here’s some code that I managed to get working to display details about the sub fields within a repeater:
Note: I left my debugging statements intact, but commented out.
<?php
// repeater field - this can be set dynamically within your loop of course... I set it statically for testing
$field_obj = get_field_object( 'field_59dbae70e1416' );
if ( $field_obj ) {
if ( $field_obj['type'] == 'repeater' ) {
// the array of sub fields within the repeater
$sub_fields = $field_obj['sub_fields'];
foreach( $sub_fields as $sub_field ) {
echo '<p>key: ' . $sub_field['key'] . '<br />';
echo 'label: ' . $sub_field['label'] . '<br />';
echo 'name: ' . $sub_field['name'] . '</p>';
}
//echo '<pre>';
//print_r($sub_fields);
//echo '</pre>';
}
}
?>
Fantastic ! I get the object.
But… there’s no value at all in this object. Well the values are NULL in this new array and so when trying to ouptut $sub_field[‘value’]
The topic ‘Absolute display of all fields’ is closed to new replies.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.