When using ACF (Advanced Custom Fields) repeater fields, the markup should look like this to initiate the loop.
<? if( have_rows('my-repeating-field) ): ?>
<? endif ?>
However, I would like to make this dynamic, meaning I use another PHP variable as part of the if() code, something like as follows:
<? $variable = get_field('my-variable-field'); ?>
<? if( have_rows("'" . $variable . "-repeating-field" . "'") ): ?>
<? endif ?>
However, this is not working. Is there a way I can do this with ACF/PHP? Seems pretty simple to me?
The problem is that you're concatenating the string in a way which would cause the end value being passed to have_rows
to have quotes inside of it. You only need to concatenate the value and the end of the string, and that should be enough.
have_rows($variable . '-repeating-field')
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.