Custom Fields
Re-Envisioned
Support MB Blocks Save meta values in database

  • Creator
    Topic
  • #16511
    closemarketing
    Participant

    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.

Viewing 10 replies - 1 through 10 (of 12 total)
  • Author
    Replies
  • #16512
    closemarketing
    Participant

    Or, Could I use meta values in template block?

    #16530
    Anh Tran
    Keymaster

    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.

    #16531
    closemarketing
    Participant

    So, I can use rwmb_meta in template block?

    #16532
    closemarketing
    Participant

    Would you add in your roadmap to save meta values as well?

    #16536
    Anh Tran
    Keymaster

    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.

    #16537
    closemarketing
    Participant

    How can i use rwmb_meta? Could you give me an example?

    #16538
    closemarketing
    Participant

    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.

    #16578
    Anh Tran
    Keymaster

    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.

    #16596
    closemarketing
    Participant

    Nice! that’s all that I need!

    Congratulations for the plugin.

    #17594
    Przemek
    Participant

    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://metabox.io/support/topic/adding-fields-to-featured-image-metabox/

Viewing 10 replies - 1 through 10 (of 12 total)
  • You must be logged in to reply to this topic.
grid gear info copy caret-up caret-down trash