Support

Account

Home Forums ACF PRO get_field() for separate groups shows value from the same group??

Solved

get_field() for separate groups shows value from the same group??

  • I have 2 groups within my block

    It all displays correctly and saves correctly. No issues.
    However, in my template I try to get the values and I get strange issues.

    
    var_dump(get_field('group_four_square_main_square_background'));
    var_dump(get_field('group_four_square_main_square_cta'));
    

    Both return the SAME values!
    var_dump

    Why?

    
    function init_four_square_fields() {
      acf_add_local_field_group([
        'key' => 'group_four_square',
        'title' => 'Four Square',
        'fields' => [
          [
            'key' => 'field_four_square_main_square_title',
            'label' => 'Title',
            'name' => 'four_square_main_square_title',
            'type' => 'text',
            'prefix' => '',
            'instructions' => '',
            'required' => 0,
            'conditional_logic' => 0,
            'wrapper' => [
              'width' => '100',
              'class' => '',
              'id' => '',
            ],
            'default_value' => '',
            'placeholder' => '',
            'prepend' => '',
            'append' => '',
            'maxlength' => '',
            'readonly' => 0,
            'disabled' => 0,
          ],
          [
            'key' => 'field_four_square_main_square_description',
            'label' => 'Description',
            'name' => 'four_square_main_square_description',
            'type' => 'textarea',
            'prefix' => '',
            'instructions' => '',
            'required' => 0,
            'conditional_logic' => 0,
            'wrapper' => [
              'width' => '100',
              'class' => '',
              'id' => '',
            ],
            'default_value' => '',
            'placeholder' => '',
            'prepend' => '',
            'append' => '',
            'maxlength' => '',
            'readonly' => 0,
            'disabled' => 0,
          ],
          [
            'key' => "group_four_square_main_square_cta",
            'label' => 'CTA',
            'type' => 'group',
            'layout' => 'block',
            'sub_fields' => [
              [
                'key' => 'link',
                'name' => 'link',
                'label' => 'Link',
                'type' => 'link',
                'instructions' => '',
                'required' => 0,
                'conditional_logic' => 0,
                'wrapper' => [
                  'width' => '50',
                  'class' => '',
                  'id' => '',
                ],
                'return_format' => 'array',
                'wpml_cf_preferences' => 2,
                'acfml_field_group_mode' => 'advanced',
              ],
              [
                'key' => 'class',
                'name' => 'class',
                'label' => 'Class',
                'type' => 'text',
                'required' => 0,
                'conditional_logic' => 0,
                'wrapper' => [
                  'width' => '50',
                  'class' => '',
                  'id' => '',
                ],
                'wpml_cf_preferences' => 0,
                'maxlength' => '255',
              ]
            ]
          ],
          [
            'key' => "group_four_square_main_square_background",
            'label' => 'Main Square Background',
            'type' => 'group',
            'layout' => 'block',
            'sub_fields' => [
              [
                'key' => 'type',
                'label' => 'Type',
                'name' => 'type',
                'type' => 'radio',
                'instructions' => '',
                'required' => 0,
                'conditional_logic' => 0,
                'wrapper' => [
                  'width' => '50',
                  'class' => '',
                  'id' => '',
                ],
                'choices' => [
                  'image' => 'Image',
                  'video' => 'Video',
                  'color' => 'Color',
                  // 'embed' => 'Embed video',
                ],
                'allow_null' => 0,
                'other_choice' => 0,
                'default_value' => 'color',
                'layout' => 'horizontal',
                'return_format' => 'value',
                'save_other_choice' => 0,
                'wpml_cf_preferences' => 0,
                'acfml_field_group_mode' => 'advanced',
              ],
              [
                'key' => 'image',
                'label' => 'Image',
                'name' => 'image',
                'type' => 'image',
                'instructions' => '',
                'required' => 0,
                'conditional_logic' => [
                  [
                    [
                      'field' => 'type',
                      'operator' => '==',
                      'value' => 'image',
                    ],
                  ],
                ],
                'wrapper' => [
                  'width' => '50',
                  'class' => '',
                  'id' => '',
                ],
                'return_format' => 'array',
                'preview_size' => 'full',
                'library' => 'all',
                'min_width' => '',
                'min_height' => '',
                'min_size' => '',
                'max_width' => '',
                'max_height' => '',
                'max_size' => '',
                'mime_types' => '',
              ],
              [
                'key' => 'video',
                'label' => 'Video',
                'name' => 'video',
                'type' => 'file',
                'instructions' => '',
                'required' => 0,
                'conditional_logic' => [
                  [
                    [
                      'field' => 'type',
                      'operator' => '==',
                      'value' => 'video',
                    ],
                  ],
                ],
                'wrapper' => [
                  'width' => '50',
                  'class' => '',
                  'id' => '',
                ],
                'return_format' => 'array',
                'library' => 'all',
                'min_size' => '',
                'max_size' => '',
                'mime_types' => '',
              ],
              [
                'key' => 'color',
                'name' => 'color',
                'type' => 'select',
                'choices' => [],
                'conditional_logic' => [
                  [
                    [
                      'field' => 'type',
                      'operator' => '==',
                      'value' => 'color',
                    ],
                  ],
                ],
              ]
            ]
          ],
        ],
        'location' => [
          [
            [
              'param' => 'block',
              'operator' => '==',
              'value' => 'acf/four-square',
            ],
          ],
        ],
        'menu_order' => 0,
        'position' => 'normal',
        'style' => 'default',
        'label_placement' => 'top',
        'instruction_placement' => 'label',
        'hide_on_screen' => '',
      ]);
    }
    
    add_action('acf/init', 'init_four_square_fields');
    
  • I found the issue,

    Turns out groups also need a ‘name’ field.
    Which makes sense in retrospect since they’re considered Repeater fields with one row.

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.