Support

Account

Home Forums General Issues Many of the same clone in another set of fields Reply To: Many of the same clone in another set of fields

  • For the most part using a group or using prefixing in ACF does the same thing to the field name. But there is one difference that can effect coding.

    I generally use group fields and I will explain why.

    Usually I create a template part for showing content from a clone. Think of it like a component.

    So let’s say have a clone with just one field in it named “field_x”

    If I use clone prefixing then my code will change every time I use the clone so that I can call “prefix_1_fied_x”, “prefix_2_field_x”, etc.

    If I use a group field then I can do this

    
    if (have_rows('group_z')) { 
      // always true, a group field is a repeater that always has one row
      while (have_rows('group_z)) {
        the_row();
        get_template_part('template-parts/components/my-component');
      }
    }
    

    and inside the my-component.php file I can always call

    
    get_sub_field('field_x')
    

    no matter what group it’s in. for one or two fields maybe not a big deal, but if you have 10 or 40 fields in your clone then you only need to code a new loop to call the component template rather then re-code all of the field calls to use the new prefixed field names.