Home › Forums › Gutenberg › Updating fields within blocks from front end. › Reply To: Updating fields within blocks from front end.
An update on this if people would like to try to do the same thing. I do have a working function to get this done, it’s a bit hacky, but it’s working. It’s in a somewhat controlled environment, so this works for what we need.
What’s being done is I’m taking the saved ACF block “JSON” from the wp_post
table and spitting it out. Upon doing that, I’m doing a find/replace of all the extra characters that aren’t necessarily JSON friendly to make it JSON friendly. Once that’s complete, I’m using json_decode()
to turn it into an editable format and update the fields that need updating. To save it, I use json_encode()
to turn it back into JSON. Once again, while it may be unnecessary, I use json_decode($var, true)
to turn it into a PHP array so I can add back the elements that are required with ACF.(<!– wp:acf/… and so fourth). Then I can save the post back to the database and successfully update my field(s) from the front end.
Hopefully this helps anyone looking to do the same, or similar thing. If you’d like me to post my code, let me know…there is probably a better way of doing this.
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!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.