Support

Account

Home Forums General Issues update_field not working for me

Solved

update_field not working for me

  • Hello Elliot,

    I’d hate to miss an opportunity to thank you for your work, so thank you, thank you, thank you.

    I don’t seem to be able to get update_field to have an effect on a post of any type. I have followed the examples shown in the update_field documentation but, for the life of me, I can’t get the field to update at all. I’m guessing from the lack of issues lodged about this that I am doing something wrong, but my code is identical to your examples. My code lives in the standard functions.php file and I’m checking that the function exists prior to using it (it does), etc.

    Ideally I want this to work on a post created with wp_insert_post() but even a pre-made page (say, with ID 355) with an ACF text field (key: field_524bc571fd532) assigned to it (via post_type == ‘page’) does not update the field’s value using:

    update_field( 'field_524bc571fd532', 'Testing', 355 );

    I know it’s impossible to debug code you don’t have access to, but can anyone advise where I might be going wrong? Or suggest how I could provide a set of test files that doesn’t require you to setup a whole WordPress instance?

  • Hi @joel_birch

    Can you confirm that your if statement is allowing your update_field function to run?

    It is most likely that you are experiencing a current limitation of ACF. That is all API functions do not work correctly in the functions.php file, before the init action.

    Does this help?

  • Hi Elliot,

    It’s definitely not the if statement as it still doesn’t work when I remove it. However, (bit of a “duh” moment for me here) it’s surely what you said about it not working before the init action. Brain-fade on my part not to try attaching the code to a hook! I’ll come back and hit the big green “solved” button as soon as I test this.

    Really appreciate your time, as always. Thank you.

    Joel.

  • Yup, that was it. Thank you so much.

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

The topic ‘update_field not working for me’ is closed to new replies.