Get Metabox Group subfield values from serialized array

Support MB Group Get Metabox Group subfield values from serialized array

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #40309
    CodogCodog
    Participant

    Hi there,
    how can I get 'subfield' values from the serialized array of a Metabox Field Group - outside of pages and posts, where the traditional:

    `get_post_meta(get_the_id(), 'meta-key', true);'

    will NOT work.

    OR

    $group_values = rwmb_meta( 'group_id' ) ?: [];
    foreach ( $group_values as $group_value ) {
        $value = $group_value[ $sub_field_key ] ?? '';
        echo $value; // Display sub-field value
    }

    wiLl also NOT work?

    Any help appreciated 🙂

    #40334
    PeterPeter
    Moderator

    Hello,

    If you use the helper function rwmb_meta() outside of a post or page, you need to pass the post/page ID to the third parameter, just like you pass the post/page ID to the first parameter of the function get_post_meta(). For example:

    $group_values = rwmb_meta( 'group_id', '', 123 )

    Please read more on the documentation https://docs.metabox.io/functions/rwmb-meta/

    #40346
    CodogCodog
    Participant

    Hi Peter,
    ok I'll give that a go.

    Cheers 🙂

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