Support

Account

Home Forums ACF PRO get_field('field')['subfield'] vs get_field('field_subfield') Reply To: get_field('field')['subfield'] vs get_field('field_subfield')

  • I don’t know why this does not work in the case of an image sub field. The only thing that I can think of is that when called that way the format_value method of the image field is not being run for some reason. Exactly what is returned by this:

    
    $groupA_image =  get_field( 'groupA')['img'];
    var_dump($groupA_image);
    

    I personally do not use shortcuts of this nature because I feel that it makes it harder to understand what’s going on when I have to look at it again in 6 months or a year.

    To be honest, I don’t event use the shortcut of

    
    get_field("{$group_name}_{$sub_field_name}")
    

    when getting the sub field of a group because when I look at this code in 6 months or a year I want to know that I’m looking at code for a group field.

    Another reason is the possibility of unpredictable results, like in this case, that might break the site after an update.