Support Forum
How can I save the meta values from the gutenberg block as a meta value?
Is it possible? That would be very nice, becouse you can use it to filter a post type or similar.
Thanks.
Or, Could I use meta values in template block?
Hi,
Unfortunately, blocks can save data only to its own. The post meta allows only 1 pair of key-value, but you can add many blocks in a post. So, if that's possible, that might be confusing.
In order to use meta values in a block template, you can simple register meta fields normally with Meta Box, and use helper functions rwmb_meta
to get them to show.
So, I can use rwmb_meta in template block?
Would you add in your roadmap to save meta values as well?
So, I can use rwmb_meta in template block?
Yes, you can.
Would you add in your roadmap to save meta values as well?
As I explain in the previous reply, this doesn't work because you can add multiple instances same block. If one field in each blog has different values, then there's no way to decide which value will be save in the post meta.
How can i use rwmb_meta? Could you give me an example?
What are the limitations for template.php? I'm trying to use rwmeta and WordPress Functions like the_excerpt, the_post_thumbnail, etc. But they does not work.
Hi, please see this video: https://www.loom.com/share/80fa3ff5dc6149a9bd2cb640a62aa69c. I demonstrate how to use rwmb_meta
, rwmb_the_value
in the block render callback.
Just a note: when you use these helper functions, don't forget to use the parameter $post_id
. If you want to use other WordPress functions, remember to use it as well, or you'll get the wrong info when preview the block in the edit screen.
Nice! that's all that I need!
Congratulations for the plugin.
If one field in each blog has different values, then there’s no way to decide which value will be save in the post meta.
Anh, I understand your point, but the fact is that blocks are created by aware developers and Gutenberg itself gives the possibility of storing data in post meta. (For example, it is enough to allow one such block per post and potential confusion is over)
I think there are many use cases for this.
An instant example from me five minutes ago: I want to create a block including editable featured image and it would be great if this advice would work in MB Blocks: https://support.metabox.io/topic/adding-fields-to-featured-image-metabox/
I second this. If multiple
is set to false
then it could work in tandem with another flag like post_meta
set to true
so that the block can save to the db as the block's ID for the meta_key
Not totally sure if it is possible but saving to the db as post_meta and rendering on the frontend at the same time would be a game changer. I need blocks for page creating but still use pieces of data on archive pages or search result like phone numbers, emails, etc.
I'm not familiar with MB Block internals, but in pure Gutenberg there are just 2 steps: registering post meta in PHP and defining "source: 'meta', meta: 'meta_field_key'" in JS block declaration. I feel that it might be not a big leap in MB code.