Retrieve ID from Post field

Support MB Blocks Retrieve ID from Post fieldResolved

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #22622
    JCJC
    Participant

    I want to build a block where I can select a CPT post in the backend and the block should display some custom fields of the selected post in the front end.

    So I created a field group with a WordPress post field, where I selected the CPT as Post Type.

    In the Render Code I want to retrieve the ID of the selected post and either send it to a php function or use the values of some custom fields of the post directly.

    When I enter this into Render Options (Code):

    <h2> Output: {{ grid_select_post }}</h2>

    It gives me a html link with the title of the post.

    How can I retrieve the ID instead?

    Thanks.

    #22625
    Long NguyenLong Nguyen
    Moderator

    Hi JC,

    Please follow this topic to know how to get the custom field value in the Render Options.
    https://support.metabox.io/topic/image-size-using-twig-block-builder/#post-22566.

    There are two cases:

    • Custom field in the block: use the function mb_get_block_field().
    • Custom field of the post which has the block: use the function rwmb_meta().
    #22626
    JCJC
    Participant

    Thank you.

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