Skip to main content
17 events
when toggle format what by license comment
Nov 19, 2021 at 23:05 comment added Tom J Nowell yes, your post meta needs to be registered, that's not a Gutenberg thing though, if your meta is not registered it will not appear in the REST API or be updatable via the REST API. Nothing you do in the block editor or JS will matter if the meta you are trying to work with is not registered. Otherwise you'll ask the block editor to save a value to the key "foo" and WP will be like "foo? Never heard of it, don't know what that is, go away" much like if you tried to use a custom post type without registering it
Nov 19, 2021 at 20:36 comment added Marc I followed the article developer.wordpress.org/block-editor/how-to-guides/metabox/… word by word and ended up with "setMeta" and "meta" to retrieve the data. Do you see another version of the article? I cleared my cache multiple times but there is no mentioning of "WP Data" or "Dispatch" or anything. It starts with "With the meta field registered in the previous step, next you will create a new block used to display the field value to the user. "
Nov 19, 2021 at 18:26 comment added Tom J Nowell you do not need to register a store to do this, WP Data can do a lot of things, but you just need what's in developer.wordpress.org/block-editor/how-to-guides/metabox/…, that article has all the missing pieces to your puzzle
Nov 19, 2021 at 18:06 comment added Marc And if this is the answer: developer.wordpress.org/block-editor/reference-guides/packages/… Wow this is really hard to understand. Maybe I am getting old but is over my head. I need to dig in the docs deeper.
Nov 19, 2021 at 17:57 comment added Marc Thank you. Could you please point me to the url where this is documented so that I learn something?
Nov 19, 2021 at 17:40 comment added Tom J Nowell so actually, the tutorial you linked to had been updated to not use the meta attributes, but instead useSelect and useDispatch to do what I suggested you do. I still think you should do it via a UI in the sidebar via a panel in the blockinspector, and there's a block inspector slot fill component that you can use to put things in that area
Nov 19, 2021 at 16:49 comment added Tom J Nowell metaboxes as a concept are something that doesn't quite fit and were put in for compatibility reasons, there is no one single thing that replaces them, it could be a panel in the block inspector, in the post inspector, or even an entire custom sidebar. I believe somebody has already asked how to update post meta in the block editor on the site
Nov 19, 2021 at 16:30 comment added Marc Thank you. Could someone mark that part as deprecated in the documentation? It is not marked as such. And what does this mean: "if you must update meta from a block that you do it by dispatching". I am a bit sad, though. Because the metabox thing was exactly the thing I thought might solve this. =(
Nov 19, 2021 at 16:21 comment added Tom J Nowell using meta as the source for a block attribute is deprecated, it was originally hoped blocks could replace metaboxes but the gutenberg team have been moving away from that for several years now, recommending instead that if you must update meta from a block that you do it by dispatching instead. You could do it this way, but I strongly advise against it, and cannot guarantee it will not need refactoring anyway in a future release to undo it
Nov 19, 2021 at 15:28 comment added Marc Ok. But look what I found: developer.wordpress.org/block-editor/how-to-guides/metabox/… Isn't this exactly my use case here?
Nov 19, 2021 at 15:23 comment added Tom J Nowell I'd register a sidebar panel in that blocks edit component and use it to update post meta. It'd be the same implementation for the panel itself wether it was in the block or elsewhere anyway. Register the meta on the server side so it's updatable via REST and then from there it's general WP components and updating the meta in the data store as you would anywhere else in the block editor
Nov 19, 2021 at 15:16 comment added Marc Alright. Thank you. I wanted to port my game review plugin "wp-shortscore" wordpress.org/plugins/wp-shortscore to a block: github.com/mtoensing/game-review Shortscore uses a panel to input the score and displays the score at the end of the post. I get a feeling that this is the best approach for this kind of problem
Nov 19, 2021 at 14:55 comment added Tom J Nowell Normally if you need to set a meta or term or anything that's attached to the post, it would be by registering a sidebar plugin or adding a panel to the post inspector. A block might fetch these values for display but while nothing prevents an edit component from setting them, it's not how the UX was intended to work.
Nov 19, 2021 at 14:53 comment added Tom J Nowell I don't know that your approach is the correct one, and it's difficult to advise without knowing the purpose of the block. And no add_post_meta adds post meta, whereas taxonomy/terms are a custom taxonomy like categories/tags. Post meta is fast when you already know the post ID. Taxonomy tables are purpose built for finding post IDs when you know the term ( the thing meta_query does but potentially hundreds of times faster and more scalable and using dedicated tables )
Nov 19, 2021 at 14:40 comment added Marc Thank Tom, as always. So how do I save the data in the taxonomy from within the blocks plugin? Is there a best-practise? Or is a meta_key with "add_post_meta( $post_ID, $meta_name, $meta_value, true ) " the same a taxonomy?
Nov 19, 2021 at 14:34 comment added Tom J Nowell you don't, blocks are just content, so this is no different to asking how do I query for posts that contain a shortcode with attributes. You were never meant to query for blocks, nevermind sort them by it. If you want to store some information then query for posts with it, you do what was always the best practice, use a term in a taxonomy. The block editor does not change that. Blocks are a sub-unit of content, and a post is the smallest chunk of content as far ass WP_Query is concerned. You can search inside a post but it is no different to searching for words in a paragraph
Nov 19, 2021 at 13:56 history asked Marc CC BY-SA 4.0