Support

Account

Home Forums Bug Reports Problem getting values from fields in group layout (Options page)

Solving

Problem getting values from fields in group layout (Options page)

  • WordPress: 4.9
    ACF Pro: 5.6.5

    Hi,

    is there any bug with using fields in group layout on option page?

    I´ve got an options page in a custom post type. Getting a single option field works fine, but I am not able to get the values from inside a group layout. When visiting the options page with get_field('my_group_layout' , 'option'); somewhere in my plugin, the group layout is gone.

    Thanks for any help.

  • A group field works like a repeater. You either need get the parent field as an array or treat it as a repeater field with 1 row. You cannot use get_field() to get the value of a sub field of the group. https://www.advancedcustomfields.com/resources/group/

  • Late reply, but maybe this will help other people:

    Instead of struggling with have_rows, do a foreach

    <?php
    $group = get_field('groupname');
    $repeater = $group['repeatername'];
    foreach($repeater as $value){
    	//inside loop / repeater
    	echo $value['fieldname']; // the field name you desire 
    
    } 
    ?>
  • I’ve learned since my original post that you can get a sub field of a group field without a loop.

    
    get_field('[GROUP FIELD NAME]_[SUB FIELD NAME]');
    
Viewing 4 posts - 1 through 4 (of 4 total)

The topic ‘Problem getting values from fields in group layout (Options page)’ is closed to new replies.