Thanks again – I’ve implemented the code successfully, and also added an additional line of code so that empty fields do not display. Here’s the final code.
<ul>
<?php
$fields = get_field_objects();
if( $fields ) {
foreach ($fields as $field_name => $field) {
if ($field['parent'] == '303') {
if ($field['value'] == '') {
continue;
}
echo '<li><b>';
echo $field['label'] . ": </b>";
echo $field['value'];
echo '</li>';
}
}
}
?>
</ul>
John, thanks so much for helping out.
I’ve run the code you suggested, and you can see the results here (under the heading Optional Extras – the other two columns are coded line by line – not ideal): https://bushlapa.storiesandscience.co.za/caravans/goggas/rooimier/
Just to take a step back – what I’d like to achieve is the following:
– Display the field names and values from one field group at a time.
– Exclude any fields that do not have a value.
Here is a snippet of the printed result:
Array
(
[dry_weight] => Array
(
[ID] => 439
[key] => field_5937f37f96261
[label] => Dry weight
[name] => dry_weight
[prefix] => acf
[type] => text
[value] => 620
[menu_order] => 0
[instructions] =>
[required] => 1
[id] =>
[class] =>
[conditional_logic] => 0
[parent] => 303
[wrapper] => Array
(
[width] => 33
[class] =>
[id] =>
)
[_name] => dry_weight
[_prepare] => 0
[_valid] => 1
[default_value] =>
[placeholder] =>
[prepend] =>
[append] => kg
[maxlength] =>
)
[total_length] => Array
(
[ID] => 440
[key] => field_5937f3b496262
[label] => Total length
[name] => total_length
[prefix] => acf
[type] => text
[value] => 3360
[menu_order] => 1
[instructions] =>
[required] => 0
[id] =>
[class] =>
[conditional_logic] => 0
[parent] => 303
[wrapper] => Array
(
[width] => 33
[class] =>
[id] =>
)
[_name] => total_length
[_prepare] => 0
[_valid] => 1
[default_value] =>
[placeholder] =>
[prepend] =>
[append] => mm
[maxlength] =>
)
I was on 5.5.10, but just updated to 5.5.14. I get the same result.
Hey John,
Thanks for helping out here! I’ve taken your code and tried to get it working. On my side the code is not running – the resulting html just leaves me with the opening and closing
What am I doing wrong?
<ul>
<?php
$fields = get_field_objects();
if( $fields ) {
foreach ($fields as $field_name => $field) {
if ($field['parent'] != 'group_5937f81f79c5b') {
// not in first group
continue;
}
echo '<li>';
echo $field['label'] . ": ";
echo $field['value'];
echo '</li>';
}
}
?>
</ul>
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.