1

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.

1 Answer 1

0

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.com/airesvsg/acf-to-rest-api/

Refer to this answer on how get the current Post ID in Gutenberg.

1
  • Thanks, @mtthias. I'm having a play with the Beta now. Feb 12, 2019 at 11:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.