MB Blocks get_the_ID() does not work in preview/gutenberg editor

Support MB Blocks MB Blocks get_the_ID() does not work in preview/gutenberg editorResolved

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #32781
    Michele SchembriMichele Schembri
    Participant

    I am currently using MB Blocks to create custom blocks that will show certain elements based on the post they are being used in. To give an example, for example, I would like to show a list of categories based on the current post. When the page is rendered on the front end, all works well as the method get_the_id() returns the post's ID, however this is not being retrieved when in Gutenberg Editor, even after the post was published (so the ID exists). Is there any alternative to get_the_ID I can use in order to be able to show data in the preview/gutenberg editor?

    Thanks!

    #32793
    Long NguyenLong Nguyen
    Moderator

    Hi Michele,

    You can use the variable $post_id with the settings render_callback or render_template to get the current post ID when you preview the custom block in the backend. Please get more details on this documentation https://docs.metabox.io/extensions/mb-blocks/#render_callback

    #32808
    Michele SchembriMichele Schembri
    Participant

    Thanks, worked like a charm.

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