sub group buttons array

Support MB Group sub group buttons arrayResolved

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #24166
    Martin RybosMartin Rybos
    Participant

    Hi.
    I would like to make foreach for button group.

     array(
                            'name'   => 'Buttons',
                            'id'     => 'sub_group_btn',
                            'type'   => 'group',
                            'clone'  => true,
                            'fields' => array(
                                // Normal field (cloned)
                                array(
                                    'name'  => 'Button',
                                    'id'    => 'buttontext',
                                    'type'  => 'text',
                                    
                                ),
                            ),
                        
                         ),

    //my code is

    if ( ! empty( $disliders ) ) {
        foreach ( $disliders as $dislider ) {        
              
         
                echo "<h3 class='move'>".$dislider['mainh']."</h3>";
                echo "<h4 class='move'>".$dislider['subh']."</h4>";
                echo "<p class='move'>".$dislider['maintext']."</p>";
                echo "<button class='move'>";
                
    $array = $dislider['sub_group_btn'];
    foreach ($array as $value) {
      echo "$value<br>";
    }
    
    print_r($array);            
                echo "</div>";              
            
        }
    }

    foreach display only array at all buttons. How could i fix it ?

    myarray

    #24167
    Long NguyenLong Nguyen
    Moderator

    Hi,

    Please follow this documentation to know how to get sub-fields value inside a cloneable group https://docs.metabox.io/extensions/meta-box-group/#getting-sub-field-value.

    The code would be:

    $array = $dislider['sub_group_btn'];
    foreach ( $array as $value ) {
      echo $value['buttontext'];
      echo '<br>';
    }
    #24168
    Martin RybosMartin Rybos
    Participant

    Thank you. Works

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