select advanced in Group showing: "Warning : Invalid argument supplied foreach"

Support MB Builder select advanced in Group showing: "Warning : Invalid argument supplied foreach"Resolved

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #11675
    AleAle
    Participant

    I have created the followimg metabox using the builder but I am having problems when trying to display on frontend.

    Metabox

    https://ghostbin.com/paste/gb8nr

    Frontend

    $values = rwmb_meta( 'cellclasses' );
    foreach ( $values as $value ) {
        echo $value;
    }

    This is the message I get on frontend:

    Warning: Invalid argument supplied for foreach()

    Is there a problem because grouping the Select Advanced fields or is there some other problem here?

    #11686
    Anh TranAnh Tran
    Keymaster

    Hi Ale,

    You're calling the field cellclasses, which is a sub-field of a group style. So the function rwmb_meta returns nothing, thus the next foreach loop doesn't work.

    You should get the value of the group style first, then get the value of sub-field. Like this:

    $style = rwmb_meta( 'style' );
    $cell_classes = isset( $style['cellclasses'] ) ? $style['cellclasses'] : array();
    foreach ( $cell_classes as $cell_class ) {
        echo $cell_class;
    }
    #11691
    AleAle
    Participant

    Thanks so much Anh, I didn't know that groups will affect how to display fields on the website.
    Now works very well.

    One more thing is that when adding multiple keys/values to select advanced the Metabox Builder does not create an array but a unique value, if I input the following on the options field:

    Red: red
    Yellow: yellow
    Blue: blue

    The Buuilder creates this and not an array:

    'options' => 'Red: red
    Yellow: yellow
    Blue: blue',
    #11700
    Anh TranAnh Tran
    Keymaster

    Hi Ale,

    I've just checked the options for select_advanced field, looks like it's buggy when put in groups. I'll fix that.

    #11707
    AleAle
    Participant

    Thanks

    #11768
    DougDoug
    Participant

    Anh - note that it's not just select_advanced that is buggy when added to a group. It's also the regular select field that shows the same behavior when placed into a group using Builder. Perhaps fixing one will fix the other. Just wanted to make sure you knew it was both field types that did this.

    #11772
    Anh TranAnh Tran
    Keymaster

    Yes, it happens for all choice fields. The problem is the Builder doesn't process sub-fields. We're trying to fix that.

    #11804
    Anh TranAnh Tran
    Keymaster

    Hi Ale, the bug is fixed in the latest version of MB Builder. Please update.

    Thanks for your bug report!

    #11813
    AleAle
    Participant

    Thank you for fixing it!

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