It's the first time I write on this forum and I'm looking for some help with displaying (or not) a table with ACF fields. I tried many solutions but I didn't find the way to resolve my problem, hope I will find it here!
I have a group field called "Total" with some number subfields "2010,2011,..." The idea is to display a table with the subfields values when at least one of these subfields has a value (this seems working) and when there are no values, no table(this is the problem).
The problem with the code I have for the moment is when there are no values, I have an empty table.
Here is the code:
$field = get_field_object('total', $curauth);
$values = get_field('total', $curauth);
if(!empty($values)) {
echo '<div class="column one"><h4>Operating budget in euros</h4>
<table>
<thead>
<tr>
<th>2010</th>
<th>2011</th>
<th>2012</th>
<th>2013</th>
<th>2014</th>
<th>2015</th>
<th>2016</th>
<th>2017</th>
<th>2018</th>
<th>2019</th>
</tr>
</thead>
<tbody>';
echo '<tr>';
foreach ($values as $value) {
echo '<td>';
echo $value;
echo '</td>';}
echo '</tr>';
echo '</tbody>
</table></div>';
}
Any help is welcome! Thanks
Aucun commentaire:
Enregistrer un commentaire