I Try to manage something like this, but the sub_field “zusatzbutton” doesn’t work.
Any thought?
<?php
$seite = get_field('seite');
$zusatzbutton = get_sub_field('zusatzbutton-check');
if($seite) {
echo '<div class="seiten grid-3 wrapper">';
foreach($seite as $s) {
echo '
<div class="seite column">
<div class="seite-bild"><a href="'.$s['button-link'].'"><img src="'.$s['seite-bild'].'"></a></div>
<h2>'.$s['seite-text'].'</h2>
<a class="weiterlesen" href="'.$s['button-link'].'">'.$s['button-text'].'</a>';
if($zusatzbutton == 'yes') {
echo '<a class="weiterlesen" href="'.$s['zusatzbutton-link'].'">'.$s['zusatzbutton-text'].'</a>';
}
echo '</div>';
}
echo '</div>';
}
?>
You can’t use get_sub_field() unless you are in a have_rows() loop. https://www.advancedcustomfields.com/resources/have_rows/
This will return an array of rows
$seite = get_field('seite');
where each element of the array is a row with nested elements for each field
example representation of this value:
$seite = array(
array(
// row 1
'zusatzbutton-check' => 1, / some value for this sub field
'second-sub-field' => 'value of this field',
// etc...
),
array(
// row 2
// etc...
)
)
Have rows loop
if (have_rows('seite')) {
while (have_rows('seite')) {
the_row();
if (get_sub_field('zusatzbutton-check')) {
// show information about this row
// for more information see the link provided for have_rows()
}
}
}