Home Forums Front-end Issues Get sub field object of field in a group?


Get sub field object of field in a group?

  • I have a wysiwyg field in one of my flexible content blocks, and I call “wysiwyg” as a class for the block with the following code:

    $content = get_sub_field('text');
    $field = get_sub_field_object('text');
    $fieldtype = $field['type']; ?>
    <div class="<?php echo $fieldtype; ?>">

    It works great, but I need to achieve the same thing with a wysiwyg field within an acf field group and I can’t get it to work the same way. This is what I have now:

    $content = get_sub_field('twi_fields');
    $text = $content['twi_text'];
    $field = get_sub_field_object('$text');
    $fieldtype = $field['type']; 
    <div class="<?php echo $fieldtype; ?>">
  • To get the field object of a group field sub field you need to treat the group field as a repeater, not as an array.

    while (have_rows('twi_fields')) {
      // always happens once on a group field
      $text = get_sub_field('twi_text');
      $field = get_sub_field_object('twi_text');
      $fieldtype = $field['type'];
Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.