Support

Account

Home Forums General Issues Get label and value of each row Group field

Solved

Get label and value of each row Group field

  • if( have_rows('specifications') ):
      echo '<table>';
       while( have_rows('specifications') ): the_row();
    		
       $row = get_row();
       echo '<pre>',print_r($row,1),'</pre>';
    
       $field = get_sub_field_object('field_60642fc912f36');
    
       echo '<tr>';
        echo '<td>'.$field['label'].'</td>';
        echo '<td>'.$field['value'].'</td>';
       echo '</tr>';
    
      endwhile;
     echo '</table>';
    endif;

    The echo '<pre>',print_r($row,1),'</pre>'; returns this:

    Array
    (
        [field_60642fc912f36] => 37 cm
        [field_60642fe412f37] => 27,5 cm
        [field_60642fee12f38] => 143 cm
        [field_6064305e3ea66] => 170 cm
        [field_606430673ea67] => 20
        [field_606430713ea68] => 25 cm
        [field_606430793ea69] => 2 cm
        [field_6064307f3ea6a] => Essenhout
        [field_606430863ea6b] => 0.8 kg
    )

    So in the function above I added the first array key to get my values and it gives me the label and value in the front-end. But I want this line :

    $field = get_sub_field_object('field_60642fc912f36');

    to be like

    $field = get_sub_field_object('DYNAMIC FILLED ARRAY KEY');

    How can I make this work?

  • I managed the write the solution:

     $array_specifications = '';
            
            if( have_rows('specifications') ):
                while( have_rows('specifications') ): the_row();
                    $row = get_row();
                    $array_specifications = $row;
                endwhile;
            endif;
        
        echo '<table>';
        foreach($array_specifications as $item) {
            $field = get_field_object(key($array_specifications));
            //echo '<pre>',print_r($field,1),'</pre>';
            echo '<tr>';
                echo '<td>'.$field['label'].'</td>';
                echo '<td>'.$item.'</td>';
            echo '</tr>';
            next($array_specifications);
        }
        echo '</table>';
Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.