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.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.