4

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!

gang
  • 1,758
  • 2
  • 23
  • 36

2 Answers2

2

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
)
geraldo
  • 562
  • 11
  • 33
-1

Did you check the flexible content add-on for ACF? I think you will find the solution in that code.

Oh, and if you find the solution please post it here, because i'm really interested in the solution. Sorry to get your hopes up by posting a not so clear answer.

VGR
  • 1
  • Use comments, wen u wanna clarify something... This's not supposed to be an answer.. – Amit Horakeri May 06 '14 at 15:25
  • Yes, I know the flexible content add-on. It is not quite what I want to achieve. Here is my question on the ACF forum: http://support.advancedcustomfields.com/forums/topic/new-acf-type-to-store-multiple-fields-or-arbitrary-data/ Maybe the answer there can help you. I didn’t have the time to try it out yet. – gang May 06 '14 at 18:10