Please can you help me with a loop through sub_fields

Support General Please can you help me with a loop through sub_fields

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #32465
    info@ceescoenen.nl[email protected]
    Participant

    Hi,

    I have this code for looping through clonable subfields.

    This is what return the print_r:
    Array ( [huis_1_featured_sf] => Array ( [0] => Een pan [1] => Een bed [2] => Een kast ) )

    The foreach is wrong, nothing is returned. What is wrong?

    <?php
    
    $group_key = 'huis_1_test';
    $sub_field_key = 'huis_1_featured_sf';
    $group_values = rwmb_meta( $group_key, ['object_type' => 'setting'], 'website' );
    
    print_r ($group_values);
    
    foreach ( $group_values as $group_value ) {
            $value = isset( $group_value[$sub_field_key] ) ? $group_value[$sub_field_key] : '';
            echo $value; // Display sub-field value
    }
    
    ?>
    #32481
    Long NguyenLong Nguyen
    Moderator

    Hi,

    You can put the function print_r() in the foreach loop to print each item to see what the value is.

    I see there are two arrays, so you need to use two foreach loops.

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