<?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:
https://www.advancedcustomfields.com/resources/get_field_object/
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?
PS:
<?php
$fields = get_fields();
if( $fields ): ?>
<ul>
<?php foreach( $fields as $name => $value ): ?>
<li><b><?php echo $name; ?></b> <?php echo $value; ?></li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
This gives me ALL fields. I just need a specific list of fields from a specific field group. That is the problem. Anybody knows how I can solve it?
2
Answers
Think the value is always NULL because you’re getting it only the group fields, not the fields from a post. Have made a few examples maybe this will help you out.