Support

Account

Home Forums Bug Reports get_field() not working with JSON in 4.1.8

Solving

get_field() not working with JSON in 4.1.8

  • 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.

  • My Field in the Database “temp_key_for_some_json” is being renamed in 4.1.8.1 to “field_some_json” (when saving that post) and after that I cannot access the fields contents any longer with get_field(‘some_json’). Why not?

  • Hi @noisyrabbit

    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?

  • Hi @elliot,

    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 4.1.8.1 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.

  • Hi @noisyrabbit

    Thanks for the feedback. I’ll do some testing and find out why the temp field key is stoping the value from being returned.

Viewing 7 posts - 1 through 7 (of 7 total)

The topic ‘get_field() not working with JSON in 4.1.8’ is closed to new replies.