Support

Account

Home Forums General Issues get_sub_field returning wrong field on ACF Pro 5.7.11

Solved

get_sub_field returning wrong field on ACF Pro 5.7.11

  • Hello

    I’ve got a repeater using the (admittedly badly named) sub fields ‘name’ and ‘text’ (the field ‘name’ being a text input, and ‘text’ being a textarea)

    If I use get_sub_field(‘text’) it is returning the content for the field ‘name’ under ACF Pro 5.7.11, but works correctly in 5.7.10.

    If I grab the contents of the parent repeater using get_field, I am able to iterate through this correctly using a foreach loop.

    As an example, let’s say that I populate the sub field ‘name’ with ‘John Smith’ and ‘text’ with some lorem ipsum

    This is returning John Smith:

    if( have_rows('portfolio') ):
    while ( have_rows('portfolio') ) : the_row();
    	the_sub_field('text');
    endwhile;
    endif;

    whereas this will correctly return the lorem ipsum:

    $repeater = get_field('portfolio');
    foreach($repeater as $pf) {
    	print_r($pf['text']);
    }

    Is this a bug, or should I just go ahead and rewrite it as a foreach?

  • I believe I’m experiencing a similar problem. Most of the images on our site broke after we upgraded to 5.7.11 because of this loop:

    while(have_rows('gallery')) : the_row();
     $image = get_sub_field('image');
     ...

    Whereas before $image contained the URL of our images, now $image is always just the letter ‘i’

    We’ve downgraded to an earlier version and hope that this is something that will get fixed with a point release…

  • Same issue here, it seems to be repeating the main field.
    downgrading to previous version fixes it.

  • Hi all.

    Thanks for the bug report. I’ll perform some testing and will report back shortly.

  • I’ve just spent some time testing a repeater field, but am unable to replicate the issues reported above. This leads me to suspect there is something else to the problem.

    Is it possible that your sites are using the register_field_group() function? We have been made aware of an issue regarding this function.

    If possible, can you please re-download the ACF PRO plugin files and test the issue?
    An easy way to re-download is to edit the main acf.php plugin file and change the version number ‘5.7.11’ down to ‘5.7.10’
    – please note the version number appears twice in this file and both will need to be changed
    – after this change is made, please update the plugin as per normal and it will update to 5.7.11 (including the new fix)

  • Whatever bug is causing this for repeaters is probably also causing get_field_objects to not capture sub_fields of field type “group”. I just submitted a ticket about this with screenshots.

  • Oh, I wasn’t running the latest version of PRO. Updating to 5.7.11 fixed my issue.

  • This reply has been marked as private.
  • @johnnycomelately

    Thanks for the update. Can you please attach an export of your field group so that I can replicate the exact issue locally?

  • How do we send you the file? would prefer not to have it stored online.

  • @johnnycomelately Please click the attachment icon (bottom left) of this comment box to display an attachment input.

  • Hi all

    My apologies for the issues in version 5.7.11.
    I am confident we have found and fixed the issue.

    Can you please re-download the ACF PRO plugin files and test the issue?

    An easy way to re-download is to edit the main acf.php plugin file and change the version number ‘5.7.11’ down to ‘5.7.10’
    – please note the version number appears twice in this file and both will need to be changed
    – after this change is made, please update the plugin as per normal and it will update to 5.7.11 (including the new fix)

  • Seems to be working for me. Cheers.

  • Same here, working now – all good!

  • Thanks for the feedback. Glad to hear things are working again!

  • I’m still experiencing an issue with missing images similar to Canton.

    Given this code, which should pull image headings and then images:

    
    <?php if (get_field('image_heading')) {
    	echo '<div class="img-heading"><h4>'.get_field('image_heading').'</h4></div>';
    }?>
    <img src="<?php $image = get_sub_field('image'); echo $image['sizes']['row-shot-big']; ?>" class="img-responsive aligncenter">
    

    The output shows as:

    <div class="img-heading"><h4>Programs in Spiritual Psychology</h4></div> <img src="" class="img-responsive aligncenter">

    The images don’t show up. This is for the non-pro version, I think. But the issue seemed similar enough to follow up here.

    Plugin Name: Advanced Custom Fields
    Plugin URI: https://www.advancedcustomfields.com/
    Description: Customize WordPress with powerful, professional and intuitive fields.
    Version: 5.7.12

Viewing 16 posts - 1 through 16 (of 16 total)

The topic ‘get_sub_field returning wrong field on ACF Pro 5.7.11’ is closed to new replies.