$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'); ?>Is it possible (and how to) query single Gutenberg blocks?|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)

Is it possible (and how to) query single Gutenberg blocks?

matteradmin8PV0评论

I have several Gutenberg blocks. I'd like them not to show up together in frontend inside the_content. I'd like to use them for other purposes, so I would need to query them (get their contents) one by one, store in memory and then place them where I want. Is it possible? Can't find docs about.

I have several Gutenberg blocks. I'd like them not to show up together in frontend inside the_content. I'd like to use them for other purposes, so I would need to query them (get their contents) one by one, store in memory and then place them where I want. Is it possible? Can't find docs about.

Share Improve this question asked Jan 29, 2019 at 10:54 Luca ReghellinLuca Reghellin 1,6522 gold badges21 silver badges45 bronze badges 1
  • i guess, if you use your custom blocks with dynamic rendering over the default JS saving, you're a step near your goal.. wordpress/gutenberg/handbook/designers-developers/… – André Kelling Commented Jan 29, 2019 at 11:15
Add a comment  | 

1 Answer 1

Reset to default 1

My own answer is: somewhat yes, but not so easily. We can use 2 functions:

https://developer.wordpress/reference/functions/parse_blocks/

https://developer.wordpress/reference/functions/render_block/

Not very well documented yet. But you can pass raw content to parse_blocks to have them back in array form.

The thing is that they don't have some sort of ID. So this approach is not always usefult, depending on what you want to do with them.

Post a comment

comment list (0)

  1. No comments so far