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
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!
🚀 This week’s session of ACF Chat Fridays dips into the preliminary results of our first ever user survey. Don’t miss it! https://t.co/3UtvQbDwNm pic.twitter.com/kMwhaJTkZc— Advanced Custom Fields (@wp_acf) May 9, 2023
© 2023 Advanced Custom Fields.