简体   繁体   English

在ACF转发器字段中使用PHP变量

[英]Using PHP variable within ACF repeater field

When using ACF (Advanced Custom Fields) repeater fields, the markup should look like this to initiate the loop. 当使用ACF(高级自定义字段)转发器字段时,标记应看起来像这样来启动循环。

<? 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: 但是,我想使它动态化,这意味着我在if()代码中使用了另一个PHP变量,如下所示:

<? $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? 有什么办法可以使用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. 问题是,您以某种方式串联字符串,这将导致将传递给have_rows的最终值包含引号。 You only need to concatenate the value and the end of the string, and that should be enough. 您只需要串联值和字符串的结尾,就足够了。

have_rows($variable . '-repeating-field')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM