I’m finding that since ACF PRO, get_sub_field_object will no longer return the labels of a ‘select field’ using the code below:
if (have_rows('example') ) : while(have_rows('example') ): the_row(); $object = (get_sub_field_object('field_object')); $value = get_sub_field('field_object'); $label = ($object['choices'][$value]); ?> <li class="<?php $value ?>"><a><?php echo $label; ?></a></li> <?php endwhile; endif;
This was working previously before the ACF PRO upgrade. Re-saving or re-creating the custom field doesn’t seem to correct this issue.
When I print_r($object) from the above example, nothing at all is displayed. It’s like the object doesn’t return anything. So the result is:
However, I noticed I have another of these loops where get_sub_field_object function appears to beworking, but it’s not in the have rows function.
if (get_sub_field('class_title') ) : $title_select = (get_sub_field_object('class_title')); $title_class = get_sub_field('class_title'); $title = ($title_select['choices'][$title_class]); echo '<h2 class="' . $title_class . ' desktop"><a href="' . $title_class . '">' . $title . '</a></h2>'; echo '<h2 class="' . $title_class . ' mobile">' . $title . '</h2>'; endif;
This is displaying the correct values and labels. print_r(title_select); gives the full array.
Hi Elliot, sorry i mixed around my responses and was providing a non-specific example. With regards to the field group code, here is the code i’m using for this:
if (have_rows('class_menu') ) : ?> <ul class="class-menu"> <?php while(have_rows('class_menu') ): the_row(); $class_select = (get_sub_field_object('menu_class')); $class = get_sub_field('menu_class'); $label = ($class_select['choices'][$class]); $link = get_sub_field('menu_link'); ?> <li class="<?php echo $class; ?>"><a href="<?php echo $link; ?>"><?php echo $label; ?></a></li> <?php endwhile; ?> </ul>
It might get a little confusing, but this works when reverted back to 4.3.8 – is it possible that the database upgrade didn’t work properly? I’m working on a localhost if that helps.
Thanks for the info. I’m interested to use your above field group code to test the issue myself, but can’t copy / paste the code due to all quotes being converted to html characters.
Are you able to edit your comment and re-post your code within
backticks to prevent the html entity issue?
Thanks for the field group, it has imported great!
I just noticed an issue with your code. Your flexible content field contains 2 layouts, however, your code does not contain any reference to the function
Perhaps the sub field code is not working, because the sub field does not actually exist for that row?
Please ignore my previous comment, I now see you had only included the inner loop. After adding in the outer loop, I can replicate the issue!
I have now fixed the issue and the function get_sub_field_object will now work with nested sub fields!
The fix is in
api-template.php line 627:
$f = acf_get_sub_field( $field_name, $row['field'] );
That should fix the issue for now until the next version is out!
Champion! That fixed the issue! Thanks! Sorry for all the replies – we got there eventually! If there are any further issues I will post entire code blocks next time!
One quick question, is your advancedcustomfields.com/my-account/ a custom built area? Is it woocommerce with a custom theme?
You must be logged in to reply to this topic.
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!