I have set up an ACF-style Gutenberg block with a couple of select fields in it. The second field is populated conditionally on the output of the first, ie, the first field is a list of posts of post type “Resource” and the second field is a list of documents attached to the Resource posts. If I choose a resource, the list of documents attached to that resource is populated into the second select box.
I’ve used the approach in this support thread to do it:
The second field is populating fine now via an ajax call. The problem is, I want to set the “selected” value in the second dropdown to the current value of the ACF field. To do that I need to know what the current value is.
I’ve tried using a lot of variations on
get_field( $post_id, $selector)
acf_maybe_get_field( $selector, $post_id );
which is what ACF is using to get the value. This doesn’t get me the value, I think because my plugin is outside the scope of the Gutenberg block environment… (ACF is doing some funky stuff with getting those values)
Can anyone please help me to get the current value of the ACF field for the specific block? I don’t mind if it’s in PHP or in the JS API – I can use either.