Get metavalue while inside the rwmb_meta_boxes hook.

Support General Get metavalue while inside the rwmb_meta_boxes hook.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #36417
    maybeadevmaybeadev
    Participant

    I am using the rwmb_meta_boxes filter hook to create metaboxes.

    But, I can't seem to get the value of a field from the post and use it in the metabox while inside that filter:

    I am getting the id of the post like this:

    $post_id = filter_input( INPUT_GET, 'post', FILTER_VALIDATE_INT );

    Then I am trying to retrieve a value from the post:

    $value= (int) get_post_meta( $post_id, 'my_value_field', true );

    Finally, I'm trying to use it as part a field defined in the metabox. But the value is always blank.

    Echoing out the value shows that the filter seems to be invoked multiple times but only once does it get the proper value but that instance is never the last time the filter is invoked.

    So how can I get a metavalue from the post and use it in the metabox (something as simple as echoing out the value to the metabox as a custom html for example). I feel like I am missing something pretty simple here.

    Thanks!

    #36439
    Long NguyenLong Nguyen
    Moderator

    Hi,

    Please try to use this code to get the post ID when registering the meta box and custom fields

    $post_id = null;
    if ( isset( $_GET['post'] ) ) {
    $post_id = intval( $_GET['post'] );
    } elseif ( isset( $_POST['post_ID'] ) ) {
    $post_id = intval( $_POST['post_ID'] );
    }

    Refer to this topic https://support.metabox.io/topic/get-post-metabox-data-inside-of-mb-block-default-value/

    #36451
    maybeadevmaybeadev
    Participant

    Hi:

    Thanks. Unfortunately, that still doesn't work.

    When I echo the value out to the error log, it looks like the filter is called four times.

    The first two times, the values are correct.

    The last two times the values are empty.

    Would appreciate any other ideas you have.

    Maybe I should only define the metaboxes if the post id is greater than zero? Would that have any side effects?

    Thanks!

    #36470
    Long NguyenLong Nguyen
    Moderator

    Hi,

    Can you please share the code that you are using on your site? Some screenshots or a screen record would be highly appreciated.

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