$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>id - Query Post Object in WP Admin|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

id - Query Post Object in WP Admin

matteradmin9PV0评论

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.

Articles related to this article

Post a comment

comment list (0)

  1. No comments so far