Custom Fields
Re-Envisioned
Support General Please can you help me with a loop through sub_fields

  • Creator
    Topic
  • #32465
    info@ceescoenen.nl
    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
    }
    
    ?>
Viewing 1 replies (of 1 total)
  • Author
    Replies
  • #32481
    Long 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 1 replies (of 1 total)
  • You must be logged in to reply to this topic.