How can I fetch the details of the $post
object of the very post that I'm working on in WP admin? I've tried global $post
but I believe that $post
is not available during editing.
A little context:
I'm digging into Gutenberg by creating my first block and coming up against an issue whereby I don't know how to query properties (type, ID) of the post in the editor. The function which outputs my content (successfully) on the front end uses ACFs get_field
to fetch a value from an ACF field on that post but fails when I attempt to display a preview of the output in the block editor in the absence of the $post->ID.
How can I fetch the details of the $post
object of the very post that I'm working on in WP admin? I've tried global $post
but I believe that $post
is not available during editing.
A little context:
I'm digging into Gutenberg by creating my first block and coming up against an issue whereby I don't know how to query properties (type, ID) of the post in the editor. The function which outputs my content (successfully) on the front end uses ACFs get_field
to fetch a value from an ACF field on that post but fails when I attempt to display a preview of the output in the block editor in the absence of the $post->ID.
The Beta of ACF 5.8 lets you create Gutenberg blocks with custom fields. You can preview these block in the editor. Sadly, you have to be an ACF-Pro customer to use the beta.
Otherwise you could try to fetch the custom fields via the REST-API utilizing this plugin: https://github/airesvsg/acf-to-rest-api/
Refer to this answer on how get the current Post ID in Gutenberg.