0

I have created a custom field type that can store my value in an array.

Everything works fine, however I created another input and pass the value as $field['additional_text'] however this updates ['value'] rather than ['additional_text'].

Array ( [value] => X [additional_text] => Y )

How do I target the correct key to pass the values to?

Astrid
  • 105
  • 12

2 Answers2

1

The solution is when you're creating your fields form inputs the name of the field must be as follows: -

name="<?php echo esc_attr($field['name']) ?>[value_x]"

value="<?php echo esc_attr($field['value']['value_x']) ?>"

name="<?php echo esc_attr($field['name']) ?>[value_y]"

value="<?php echo esc_attr($field['value']['value_y']) ?>"

This will allow you to store multiple values in your custom field type.

Astrid
  • 105
  • 12
0

You can use ACF's get_field() and update_field() function to get and set the value. You can also manipulate the field with get_post_meta() and update_post_meta() function.

Actually ACF store two values for each meta field. For example if I added 'price' custom field with ACF then 'price' and '_price' 2 post meta fields are created in database. As you know meta_key that has underscore prefix is not listed on edit post page Here real value is saved in 'price' field.

  • Hmmm, when I tried this, using update_field() it only updates the value key not the additional_text key value. – Astrid Dec 16 '18 at 18:10