I’m adding some fields with filter, I have 2 fields with “custom” save format.
array ( 'key' => 'google_code', 'label' => __('Google Analytics','trf'), 'name' => 'google_code', 'type' => 'textarea', 'formatting' => 'none', 'instructions' => __('Paste your Google Analytics code without the <script></script> tags','trf'), 'required' => '0', ), array ( 'label' => __('Favicon','trf'), 'name' => 'favicon', 'type' => 'file', 'key' => 'favicon', 'save_format' => 'url', 'library' => 'all', ),
But neither the “Google Code” nor “Favicon” returns the data correctly using for example:
it returns the attachment ID (as it is default) or the text of the textarea with (<br />) as it is per default.
Any ideas or is it a plugin issue?
Assuming you’re using this in the ‘register_field_group()’ function? What is your field group setting(s)? Is the data saving to the database correctly?
EDIT: I think I read your question wrong (or too quickly).
ACF won’t automatically recognize a custom save_format – you’ll have to add this in yourself via a custom field type. I would take a look at the textarea field class and modify the ‘format_value_for_api()’ method (in your custom field type class).
I’m using the textarea and the file type (default in the plugin). I’m exporting them for my proposes (https://github.com/jepser/The-Royal-Framework), my location and options for the group is:
'location' => array ( array ( array ( 'param' => 'options_page', 'operator' => '==', 'value' => 'acf-options-framework', 'order_no' => 0, 'group_no' => 0, ), ), ), 'options' => array ( 'position' => 'normal', 'layout' => 'no_box', 'hide_on_screen' => array ( ), ), 'menu_order' => 0,
Then, I used the code in the export section, but change the “key” for these fields.
I didn’t understand ‘format_value_for_api()’ when I wrote “custom” I’m trying to point that isn’t the default save_format.
I want get_field to return:
– in favicon just the URL
– google_code the text without any formatting
If ACF is not correctly formatting the value, that means ACF is not able to load the correct field object when you use the get_field function.
When you save a value with ACF, 2 values are saved:
1. The values
2. A reference string which connects the value to the field object
It is most likely that the values have been saved before you changed the key. After changing the field key’s, the reference does not work and ACF is not able to load the field / format the value.
Does this sound like it is possible?
The topic ‘save_format in PHP doesn't work’ is closed to new replies.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
© 2022 Advanced Custom Fields.