Post Meta Field Block inside Query Loop block in Gutenberg/FSE

Support General Post Meta Field Block inside Query Loop block in Gutenberg/FSE

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #36049
    brandonjpbrandonjp
    Participant

    Hi everyone. I'm not sure where to put this, but wanted to share because I have struggled to find a good solution. Feel free to delete this post if it is not helpful.

    In most cases, Meta Box & especially MB Views is the best solution for everything! 🙂 Except when you want to quickly render post meta inside a Query Loop block in the Gutenberg block editor. (Yes, you can create your own query loop in MB Views and use that to output construct and render a layout for a custom post type, and that's GREAT and easy, but can require a little more custom styling. And when using the Gutenberg block editor, if you put a shortcode inside of a Query Loop block, the post_id passed to your shortcode is for the parent page, not the current post in query loop. Which makes it hard to do display custom fields for custom post types quickly/easily inside the block editor. )

    SOLUTION!: Meta Field Block By Phi Phan. This plugin provides a block where you can enter any custom field ID to display it. Note that it doesn't render the meta whilst editing (and it can even be hard to find the block once you've placed it). But overall, it works reliably and works well with Meta Box -- https://wordpress.org/plugins/display-a-meta-field-as-block/

    I'm guessing this is an issue that will be solved by MB and WP in the near future, but until this, this plugin saved me a ton of time.

    #36052
    Long NguyenLong Nguyen
    Moderator

    Hi Brandon,

    Yes, the variable $post_id when you use the render_callback or render_template is the current post/page ID (parent page), not the post ID in the custom query loop. But if you create a custom query loop, you can also pass the current post ID in the loop to the View shortcode as well with a few lines of code.
    The main problem is you need to separate the variable name to use the post ID easily and avoid confusion.

    #36513
    SamSam
    Participant

    Thank you @brandonjp for the plugin recommendation. You helped solve a headache I'd been dealing with, too.

    #36779
    Attachmedia SACAttachmedia SAC
    Participant

    I was dealing with this too. Thankyou @brandonjp

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.