0

I have created custom field type following this documentation https://www.advancedcustomfields.com/resources/creating-a-new-field-type/ and I have below fields:

  • YouTube ID(input type text)
  • Submit Button(input type submit)
  • Title(input type text)
  • Description(input type text)
  • Thumbnail URL(input type text)
  • Upload Date(input type text)
  • Duration minute(input type number)
  • Duration seconds(input type number)

I have saw this question, Advanced Custom Fields – Custom Field Type with multiple inputs and ACF: Creating Custom Field Type store two values. I am expecting that I could do it this way when setting the fields.

<input type="text"
  name="<?php echo esc_attr($field['name']['youtube-id'])?>"
  value="<?php echo esc_attr($field['value']['youtube-id'])?>"
/>
 <input type="text"
  name="<?php echo esc_attr($field['name']['youtube-title'])?>"
  value="<?php echo esc_attr($field['value']['youtube-title'])?>"
/>
...

But this give me an error: enter image description here

luna moonfang
  • 459
  • 1
  • 4
  • 12

1 Answers1

0

$field['name'] is a string. Thus, doing $field['name']['foo'] or the equivalent 'string'['foo'] is illegal in PHP and will raise the error. You may want to consider something like this instead:

<input type="text"
  name="<?php echo esc_attr($field['name']); ?>"
  value="<?php echo esc_attr($field['value']); ?>"
/>
Wongjn
  • 8,544
  • 2
  • 8
  • 24