Home Forums General Issues List all sub fields of a group (field type)


List all sub fields of a group (field type)

  • Hi,

    on a single page “Instrument” (custom post type), I’ve made a field type group called “Caractéristiques”, with 12 sub fields (Corps, Cordes, Vernis, etc…).

    I’m trying to display a list of those sub fields (if not empty) with “Label” : “Value”.


    Corps : Chêne
    Cordes : Nylon
    Vernis : Brillant

    With this code, it was almost OK, but I have fields name instead of labels :

    if( have_rows('acf-spec-instru') ): 
      while( have_rows('acf-spec-instru') ): the_row(); 
      $subfields = get_field('acf-spec-instru'); 
        if( $subfields ) { ?>
            foreach ($subfields as $spec => $value) {
              if ( !empty($value) ) { ?>
                <li><?php echo $spec; ?> : <?php echo $value; ?></li>
              <?php }
            } ?>
        <?php }

    I know that I need to use get_sub_field_object() to get labels but I can’t figure it out how to use that function for all sub fields…

    Any ideas ?

    Thanks you.

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.