I am trying to create a new field type for ACF that contains multiple inputs or stores an array of values. The reason is that I would like to have some interactivity and a custom layout for a group of input fields.
I followed this tutorial http://www.advancedcustomfields.com/resources/tutorials/creating-a-new-field-type/ and used the provided template: https://github.com/elliotcondon/acf-field-type-template which is really nice and well documented. Storing one value is pretty simple. I am using only this function from the template:
function create_field( $field )
{
echo '<textarea id="' . $field['id'] . '" rows="4" class="' . $field['class'] . '" name="' . $field['name'] . '" >' . $field['value'] . '</textarea>';
}
What do I have to change in order to use two or more inputs? Thanks!
The names and values of your 2 textareas must be as follows:
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 can be chosen freely by you.
This will save multiple values in your custom field type, value will save an array like:
Array
(
[textarea1] => abc
[textarea2] => xyz
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With