Home Forums General Issues acf/save_post not working with calculated update_field Reply To: acf/save_post not working with calculated update_field

  • On the backend of the site we have ACF Fields/Groups, and the groups are assigned to show on these posts. The fields have no default value defined in ACF, we define the values by the first code block, which copies the data from an options page and the author page. We do this because each post needs to stay the same in the future, even if the data on the options page changes.

    The issue occurs when making a new post (either through the backend or acf_form frontend). So we don’t manually input any data in these fields, but they are updated programmatically when creating the post. I am already defining each variable with get_field($field_key,$post_id) as mentioned above.

    I have found there are some fields that just aren’t able to get_field() when the calculation is made the first time, and that is what is causing the issue. Once the save is completed the then empty fields are defined, so saving again allows the calculation to process correctly.

    I assumed that since the calculations (code block 2) were happening after the fields are defined (code block 1), then the calculations should be able to pull that data. Is this a bug? If not, then what’s the purpose of having acf/save_post priorities if fields aren’t updated in the order your would expect?

    Can you think of any methods where I can make this data available? If there are not any clean methods, is there anything “hacky” you could think of, like mimicking/forcing a post to save twice programmatically on it’s initial creation (the first save)?