Custom Fields
Support Meta Box Group Grouped Products to Front End Help

  • Creator
  • #940

    Can someone help me with outputting of my content from my group?

    This is my code:

    $product_group = rwmb_meta( 'products' ); 
    $sku_key = 'sw_swsku'; 
    $sku_value = isset( $product_group[$sku_key] ) ? $product_group[$sku_key] : false;

    And this is the results of my var_dump()

    var_dump( $product_group); 
    array (size=1) 
    0 => 
    array (size=4) 
    'sw_swsku' => string 'ip616gray' (length=9) 
    'sw_swdescription' => string 'Apple iPhone 6 16Gb Space Gray' (length=30) 
    'sw_swprice' => string '984' (length=3) 
    'sw_swqty' => string '1' (length=1) 
    var_dump( $sku_key  ); 
    string 'sw_swsku' (length=8) 
    var_dump( $sku_value ); 
    boolean false
Viewing 2 replies - 1 through 2 (of 2 total)
  • Author
  • #941

    Ok, I have it displaying, but it will only show the first item not the other repeater fields when multiple items added to the field

    This is how I got it to work so far

    $product_group = rwmb_meta( 'products' );
    $sku_key = 'sw_swsku';
    $sku_value = isset( $product_group[0][$sku_key] ) ? $product_group[0][$sku_key] : false;
    Anh Tran


    From the output above, I guess you have a cloned group. So the value returned from rwmb_meta for group field is an array (of clones), each element of which is an array of sub-fields' values.

    To get value for the fields, you can use the code below:

    $sku_key = 'sw_swsku';
    $product_group = rwmb_meta( 'products' );
    foreach ( $product_group as $product )
        $sku_value = isset( $product[$sku_key] ) ? $product[$sku_key] : false;
        echo $sku_value;
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Grouped Products to Front End Help’ is closed to new replies.