Hi
I’m trying to dynamically add options to a select field on the admin page (edit page) via jquery/javascript. The idea is to be able to select a layoutblock from another page (fetched via rest api) so i can link to that section.
So far that works – the only problem with the dynamically added select options is that i can only save the value per option and not the label in the database.
I’m not able to save a different value and label. The value is automatically saved as label.
I tried both with normal select and select2 field – the behavior is the same.
Any hints on that?
ACF does not save both the value and the label of values in a select field, it only saves the value. ACF depends on the field settings when returning the label and gets them from the $field[‘choices’] setting. For ACF to return the labels that are different from the values you would need to permanently update the field settings for the field.
In this case you would have to use an acf/format_value filter to change the label returned by ACF.