I would like to know if it’s already possible to hide some fields depending on the block style. Has anyone ever done it by overriding some settings in the WordPress JS API? otherwise, it would be super cool to add that as a conditional check per field or simply each block style having a different ACF location… 🤔
I’m also interested to know how this might be done. Same goes for the new block variations, which is really cool.
I just found my question by searching again for this as I need it again for another project and I didn’t remember I had already asked. 💀
I really would like this. I’ve noticed there’s talk about an ACF_Location overhaul in 5.9, but we have yet to learn what it entails.
Alright, I got an OCD moment because I come back to this post every 6 months checking in if it’s been done so I wanted to give it a go.
I’m 99% there with only filters: https://gist.github.com/davidwebca/efe3bb9f69df0a0f007179c59872054a
With that, it works on full reload of the page in the admin, but not with changes, style changes or AJAX re-rendering… And you have to visit a Gutenberg page to activate the block styles cache, otherwise there’s no way WordPress knows about the block styles registered (🙄).
Just for reference, I found this post in the forum from John about extending acf.ajax to be able to trigger the re-rendering of the form. I’ll look into that, even though his example is a broken link, I’m pretty sure I know what to do. https://support.advancedcustomfields.com/forums/topic/custom-location-rule-js-refresh/
Aaaand I figured it out. Warning: this is very much hacked around. We should never access React instances from the outside and call their methods without having been passed the instance from an event or something. But until we get the proper hooks and APIs from ACF and WP core, this is pretty much as close as it gets. https://github.com/davidwebca/acf-block-style-location
You must be logged in to reply to this topic.
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!
© 2022 Advanced Custom Fields.