我正在尝试为 ACF 创建一个新的字段类型,其中包含多个输入或存储值数组。原因是我希望为一组输入字段提供一些交互性和自定义布局。
我按照这个教程http://www.advancedcustomfields.com/resources/tutorials/creating-a-new-field-type/ http://www.advancedcustomfields.com/resources/tutorials/creating-a-new-field-type/并使用提供的模板:https://github.com/elliotcondon/acf-field-type-template https://github.com/elliotcondon/acf-field-type-template这真的很好并且有据可查。存储一个值非常简单。我只使用模板中的这个函数:
function create_field( $field )
{
echo '<textarea id="' . $field['id'] . '" rows="4" class="' . $field['class'] . '" name="' . $field['name'] . '" >' . $field['value'] . '</textarea>';
}
为了使用两个或多个输入,我必须更改什么?
谢谢!
2 个文本区域的名称和值必须如下所示:
echo '<textarea id="' . $field['id'] . '" rows="4" class="' . $field['class'] . '" name="' . $field['name'] . '[textarea1]" >' . $field['value']['textarea1'] . '</textarea>';
echo '<textarea id="' . $field['id'] . '" rows="4" class="' . $field['class'] . '" name="' . $field['name'] . '[textarea2]" >' . $field['value']['textarea2'] . '</textarea>';
textarea1
and textarea2
可以由您自由选择。
这将在您的自定义字段类型中保存多个值,值将保存一个数组,例如:
Array
(
[textarea1] => abc
[textarea2] => xyz
)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)