id - Query Post Object in WP Admin

admin2025-06-03  3

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.

Share Improve this question asked Feb 8, 2019 at 14:32 Kevin NugentKevin Nugent 5631 gold badge8 silver badges20 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 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/airesvsg/acf-to-rest-api/

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

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1748923785a314858.html

最新回复(0)