Only getting the last value from a group field

Support Meta Box AIO Only getting the last value from a group fieldResolved

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #41807
    YasmineYasmine
    Participant

    Hi there,

    I am using:

    $groups = rwmb_meta( 'academicrecommendation_multiple', '', $post->ID );
    foreach ( $groups as $group ) {
    $recommendations1 = $group[ 'academicrecommendation' ] ?? '';
    };

    to get the values from a cloneable group field. But it is only getting the last one, what am I doing wrong?

    Many thanks,
    Yasmine

    #41816
    PeterPeter
    Moderator

    Hello Yasmine,

    I've tried to export the field group on your staging site and import it on my demo site. After adding the field value and using the code, I see the subfield values display on the frontend correctly.
    You can try to create another field group and check this issue again.

    #41834
    YasmineYasmine
    Participant

    Thanks, I was trying to output elsewhere for this one, and found that I needed to do:

    $groups = rwmb_meta( 'academicrecommendation_multiple', '', $post->ID ) ?? '';
    	$recommendations = [];
    foreach ( $groups as $group ) {
    $recommendation = $group[ 'academicrecommendation' ] ?? '';
    	$recommendations[] = $recommendation;
    
    };
    	
    $all_recommendations = '<ul><li>' . implode('</li><li>', $recommendations) . '</li></ul>';

    To get what I needed. But this all works!

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