Custom Fields
Re-Envisioned
Support Meta Box Builder select advanced in Group showing: "Warning : Invalid argument supplied foreach"

This topic contains 8 replies, has 3 voices, and was last updated by  Ale 3 months, 2 weeks ago.

  • Creator
    Topic
  • #11675
    Resolved
    Ale
    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?

Viewing 8 replies - 1 through 8 (of 8 total)
  • Author
    Replies
  • #11686

    Anh 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

    Ale
    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 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

    Ale
    Participant

    Thanks

    #11768

    Doug
    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 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 Tran
    Keymaster

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

    Thanks for your bug report!

    #11813

    Ale
    Participant

    Thank you for fixing it!

Viewing 8 replies - 1 through 8 (of 8 total)

You must be logged in to reply to this topic.