Mb block function not returning the Post id

Support MB Blocks Mb block function not returning the Post id

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #36942
    Gene TeiglandGene Teigland
    Participant

    Hi,

    I'm trying to get the custom fields under the post type I have created through Metabox.

    Here is the scenario -
    I created a post type called accordion and created content within it.
    Created some custom fields under that post type named as title, content etc.
    Now I created a block of custom fields(select field) that I will display under the page editor as a block and I selected the post type filter within it. The select field has all the posts of that post type as a list.
    Now I called a render callback php function, so that function I have write in functions.php. I'm trying to get the selected item(post that is selected in the select field) post id in the rendered function but not able to get it.
    Please help me on this.

    Code in functions.php-
    ----------------------------------------
    function display_block($attributes, $is_preview = false, $post_id = null){

    var_dump($attributes);
    var_dump($post_id); //I need to get the selected item post id here
    $postid = $attributes['name'];

    echo 'inside here';

    }
    -----------------------------------------------

    Screenshot of the block field-
    https://tinyurl.com/2dl2od3z

    Screenshot of the block in page -
    https://tinyurl.com/26tsf3cy

    Screenshot of the post type content -
    https://tinyurl.com/2al84jdj

    Thank you

    #36963
    Long NguyenLong Nguyen
    Moderator

    Hi,

    The passing variable $post_id is the ID of the current editing post that you add the block to the post content.

    If you want to get the selection post ID (field value), please use the function
    mb_get_block_field( 'field_id )

    Read more on the documentation https://docs.metabox.io/extensions/mb-blocks/#render_callback

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