In 4.1.6 the following works for me (some_json is a simple textfield):
update_field('some_json', json_encode($array), $post_id); $json = get_field('some_json', $post->ID);
When I update to 4.1.8, get_field() returns false although the JSON is still stored in the Database (the same way as with 4.1.6) and nothing else changed on our end.
It might be a similar issue as it is in http://support.advancedcustomfields.com/forums/topic/get_field-cant-retrieve-new-post-saved-with-update_field-in-acf-4-1-8/ as the field_key is “temp_key_for_some_json”.
How can I achieve that the Key is “some_json” and not “temp_key_for_some_json”? I have created the field “some_json” through PHP and not the GUI.
Thanks for the bug report.
I’ll do some testing and let you know what I find.
Before you run the update_field function, does the post already have a value for some_json? If so, was that value saved through the ACF interface? Can you confirm that the correct field reference is saved under the value in the database?
Thank you for your response. My problem does still exist.
Before you run the update_field function, does the post already have a value for some_json?
Yes, the post already has a value for some_json.
If so, was that value saved through the ACF interface?
No, I have set it via PHP with update_field(), as described in my first post.
Can you confirm that the correct field reference is saved under the value in the database?
The Key in my database is currently “temp_key_for_some_json”. With 126.96.36.199 is being renamed to “field_some_json” (when saving that post) and after that I cannot access the fields contents any longer with get_field(“some_json”).
It seems that I can fix this weird issue, when I do the following:
update_field(‘some_json’, json_encode($array), $post_id);
update_post_meta($post_id, ‘_some_json’, ‘some_json’, ‘field_some_json’);
After renaming the Value from “field_some_json” to “some_json”, I can access it with get_field(‘some_json’); again.
The topic ‘get_field() not working with JSON in 4.1.8’ 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.