Hello!
I have set up an Oxygen Repeater elment. I know need to create a bit of php code to get a subfield of the repeater in a specific way. I have tried this with the following code:
<?php if( have_rows('veranstaltung_treffpunkt') ): ?>
<?php while( have_rows('veranstaltung_treffpunkt') ): the_row(); ?>
<?php
// vars
$value = get_sub_field('what3words');
$str2 = ltrim($value, '/');
?>
<a href="https://w3w.co/<?php echo $str2; ?>">/// <?php echo $str2; ?></a>
<?php endwhile; ?>
<?php endif; ?>
The problmen now is, that all the sub field values are shown underneath each repeated element. Kinda creating a loop inside a loop.
Is there a way, to just call the specific subfield value of the specific row, which is generated from the oxygen repeater element? So that I can use the code-block within the repeated element?
Thanks very much for your help 🙂
Only if you can pass that value to the PHP code. I don’t know anything about the builder you’re using so I can’t answer that.
Normally in php I would do something like this to only show a specific row.
<?php if( have_rows('veranstaltung_treffpunkt') ): ?>
<?php while( have_rows('veranstaltung_treffpunkt') ): the_row(); ?>
<?php
if (get_sub_field('some-field') == $passed_value)) {
// vars
$value = get_sub_field('what3words');
$str2 = ltrim($value, '/');
}
?>
<a>">/// <?php echo $str2; ?></a>
<?php endwhile; reset_rows(); ?>
<?php endif; ?>
Hello! Thanks again! Sometimes the easy approach actually works.
<?php
// vars
$value = get_sub_field('what3words');
$str2 = ltrim($value, '/');
?>
<a href="https://w3w.co/<?php echo $str2; ?>">/// <?php echo $str2; ?></a>