New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
update_field() not working within acf/update_value filter #440
Comments
Hi @kmcaloon Thanks for the topic. Yes, this issue is indeed due to the special circumstances of saving a field within the scope of a block. During this save event, ACF will set up a "net" to capture all save/update requests from the The solution is simple. Instead of using the ACF function |
Thanks @elliotcondon So actually originally I was using There are a couple of use cases here, but the one I am immediately dealing with is trying to set up global/reusable blocks. There are a few reasons why I would like to achieve this in a custom way rather than using the block editors native setup. So basically when an admin is editing the block anywhere within the post type, I need that data to save somewhere where I can reference it globally. Using just options, it gets dicey when needing to use repeaters, groups, and basic any field with formatting options. I guess there are no other work arounds here and I might have to tru the block editor's reusable blocks? |
Thanks for the additional info! Your solution of saving both the "value" and "reference value" is a good one, and will allow ACF to lookup the related field for that value, which in turn will allow various filters and formatting to run. On review of our "magic net" logic, I can confirm that we are catching "all" values that are saved during a block update, and not just those related to that block's ID. Perhaps there is an opportunity here to both fix your specific issue and improve the compatibility of our code. Please leave this with me and I'll add this to our to-do list. |
Thanks @elliotcondon. So I wasn't clear, the value/reference value in the options table actual didn't work for me. The options were saving but Thanks again. |
Quick update, my ugly solution is working.
|
I've just been hitting this wall for the last couple of hours and just couldn't wrap my head around it... Maybe the corresponding docs could include a passage that hints at this behaviour? Would be very helpful IMO. |
I've been trying a couple of different things here. Whenever a field prepended with
option_
is saved, I would like to not only save it to the post/block where it is being updated, but also save it as a global "acf option". I have a demo set up with a registered gutenberg block with the fieldoption_demo
. The following code doesn't seem to do the trick. I even tried toupdate_field
for the first post in my WP install, and it wouldn't save there either:Could the problem be related to the fact that the update initiating this whole is within a gutenburg block?
The text was updated successfully, but these errors were encountered: