Support

Account

Forum Replies Created

  • Temporary workaround for anyone else having this issue:

    function coerce_array_to_value( $value, $post_id, $field ) {
      if (
        $field['return_format'] === 'value' &&
        !$field['multiple'] &&
        is_array( $value ) &&
        array_key_exists( 0, $value )
      ) {
        $value = $value[0];
      }
    
      return $value;
    }
    
    add_filter( 'acf/load_value/type=select', array( $this, 'coerce_array_to_value' ), 10, 3 );
  • I’m still having this problem, even after upgrading to 5.7.1.

    It’s exactly as @room34 describes it: A select set to return “value”. On posts that haven’t yet been saved with the new value, I’m expecting no value at all, but getting a 1-length array with the first item as the value.

    This is tough to work around, because we’re trying to introduce a feature without having to touch existing posts. I’ll post a bug report.

  • Thanks for the info @jenwachter .

    FWIW, I’ll post here the fix to somewhat unrelated bugs I was experiencing with revisions that arose from trying to set the title of posts dynamically (based on ACF fields) on save.

    If you try to set native WP fields in a save_post hook (or even acf_save_post), you’ll end up with “extra” bogus revisions, often which don’t restore properly, or restore but ignore ACF changed fields.

    My fix was to listen for the wp_insert_post_data event, which I think ACF itself rides on, and make my change there, only referring to ACF fields by their ID since they wouldn’t be accessible via get_field at this point.

    
    // Update dynamic title on save.
    function bio_dynamic_title( $data, $postarr ) {
        // Bail if this isn't the right post type or if ACF wasn't submitted.
        if ( $data['post_type'] !== 'bio' || !array_key_exists( 'acf', $postarr ) ) {
          return $data;
        }
    
        $title = sanitize_text_field( full_name(
          $postarr['acf']['field_587e607692f49'], // first_name
          $postarr['acf']['field_589a17cb1cdd3'], // middle_initial
          $postarr['acf']['field_587e609192f4a'], // last_name
          $postarr['acf']['field_587e6ee94602b'] // suffix
        ));
    
        $data['post_title'] = $title;
        $data['post_name'] = sanitize_title( $title );
    
        return $data;
      }
      add_filter( 'wp_insert_post_data', 'bio_dynamic_title', 10, 2 );
    
  • Some further information after looking through stack traces: the warning is because WP, as part of restoring a revision, is calling normalize_whitespace() (which then calls trim()) on the values of ACF fields that are arrays, not strings.

    Two instances of ACF fields that triggered this:
    – A flex content’s base field
    – A list of categories selected from a taxonomy field

  • I’m also getting these warnings when trying to restore revisions on a custom post type (also with the main editor hidden via ACF). Two versions I can verify display this problem: 5.5.10 and 5.5.14.

    This is all because of a more primary bug I’m trying to troubleshoot: restoring revisions on custom post types seems to succeed, but all values in ACF fields stay the same instead of reverting.

    I’ll keep at it and post if I have any further info on either of these (what appear to be) bugs…

  • For anyone suffering from this, I have a workaround that helps my particular case until the bug is fixed. This basically triggers a javascript “change” event on the Select2 component, which snaps the conditional logic into shape. This will only work for when there is at least one item in the select.

    
    function acf_fix_select2( $field ) {
      if (
        !$field['ui'] ||                          // field isn't select2
        strpos( $field['id'], 'acfcloneindex' )   // field is hidden <select>
      ) {
        return;
      }
    
      ?>
        <script type="text/javascript">
          jQuery(function(){
            jQuery('#s2id_<?php echo $field['id']; ?> .select2-choices input:first')
              .trigger('change');
            acf.unload.off();
          });
        </script>
      <?php
    }
    add_action( 'acf/render_field/type=select', 'acf_fix_select2', 10, 1 );
    
  • I have come across another instance of conditional logic acting weird on 5.2.6.

    Add a stylized multi-select, and then add fields conditionally shown based on the value of the select. After saving, it seems the fields that should show based on the multiselect values disappear. They come back if you add/remove items, but is never shown correctly on first page load.

    Version 5.2.5 doesn’t have this bug.

  • What will be the target version in which this bug will be fixed?
    This is a huge issue for us right now.

    Agreed. This is forcing us to downgrade/deliberately keep ACF out of date on every site we use it.

  • I can also confirm having pulled hair due to this. Please update the documentation for render_field!

  • Results from get_options call:
    
        Array(
        [main_ad_-_image] => Array
            (
                [id] => 25
                [alt] => TEST
                [title] => lg-social_media
                [caption] => 
                [description] => 
                [mime_type] => image/png
                [url] => {urlhere}
                [width] => 460
                [height] => 260
                [sizes] => Array
                    (
                        [thumbnail] => {urlhere}/wp-content/uploads/lg-social_media-150x150.png
                        [thumbnail-width] => 150
                        [thumbnail-height] => 150
                        [medium] => {urlhere}/wp-content/uploads/lg-social_media-220x124.png
                        [medium-width] => 220
                        [medium-height] => 124
                        [large] => {urlhere}/wp-content/uploads/lg-social_media.png
                        [large-width] => 460
                        [large-height] => 260
                    )
    
            )
    
        [main_ad_-_url_type] => ext
        [main_ad_-_url] => www.google.com
        [small_ad_1_-_image] => Array
            (
                [id] => 28
                [alt] => Fake Text
                [title] => fake-text
                [caption] => 
                [description] => 
                [mime_type] => image/png
                [url] => {urlhere}/wp-content/uploads/fake-text.png
                [width] => 220
                [height] => 120
                [sizes] => Array
                    (
                        [thumbnail] => {urlhere}/wp-content/uploads/sm-fake-text-150x120.png
                        [thumbnail-width] => 150
                        [thumbnail-height] => 120
                        [medium] => {urlhere}/wp-content/uploads/sm-fake-text.png
                        [medium-width] => 220
                        [medium-height] => 120
                        [large] => {urlhere}/wp-content/uploads/sm-fake-text.png
                        [large-width] => 220
                        [large-height] => 120
                    )
    
            )
    
        [small_ad_1_-_url_type] => ext
        [small_ad_2_-_image] => Array
            (
                [id] => 30
                [alt] => Fake Text 2
                [title] => fake-text2
                [caption] => 
                [description] => 
                [mime_type] => image/png
                [url] => {urlhere}/wp-content/uploads/fake-text2.png
                [width] => 220
                [height] => 120
                [sizes] => Array
                    (
                        [thumbnail] => {urlhere}/wp-content/uploads/fake-text2-150x120.png
                        [thumbnail-width] => 150
                        [thumbnail-height] => 120
                        [medium] => {urlhere}/wp-content/uploads/fake-text2.png
                        [medium-width] => 220
                        [medium-height] => 120
                        [large] => {urlhere}/wp-content/uploads/fake-text2.png
                        [large-width] => 220
                        [large-height] => 120
                    )
    
            )
    
        [small_ad_1_-_url] => www.google.com
        [main_ad_-_page] => {urlhere}
        [small_ad_2_-_url_type] => ext
        [small_ad_2_-_url] => www.google.com
        [small_ad_3_-_image] => Array
            (
                [id] => 27
                [alt] => Fake Text 3
                [title] => fake-text3
                [caption] => 
                [description] => 
                [mime_type] => image/png
                [url] => {urlhere}/wp-content/uploads/fake-text3.png
                [width] => 220
                [height] => 120
                [sizes] => Array
                    (
                        [thumbnail] => {urlhere}/wp-content/uploads/fake-text3-150x120.png
                        [thumbnail-width] => 150
                        [thumbnail-height] => 120
                        [medium] => {urlhere}/wp-content/uploads/fake-text3.png
                        [medium-width] => 220
                        [medium-height] => 120
                        [large] => {urlhere}/wp-content/uploads/fake-text3.png
                        [large-width] => 220
                        [large-height] => 120
                    )
    
            )
    
        [small_ad_3_-_url_type] => ext
        [small_ad_3_-_url] => www.google.com
        [small_ad_4_-_image] => Array
            (
                [id] => 29
                [alt] => Fake Text 4
                [title] => fake-text4
                [caption] => 
                [description] => 
                [mime_type] => image/png
                [url] => {urlhere}/wp-content/uploads/fake-text4.png
                [width] => 220
                [height] => 120
                [sizes] => Array
                    (
                        [thumbnail] => {urlhere}/wp-content/uploads/fake-text4-150x120.png
                        [thumbnail-width] => 150
                        [thumbnail-height] => 120
                        [medium] => {urlhere}/wp-content/uploads/fake-text4.png
                        [medium-width] => 220
                        [medium-height] => 120
                        [large] => {urlhere}/wp-content/uploads/fake-text4.png
                        [large-width] => 220
                        [large-height] => 120
                    )
    
            )
    
        [small_ad_4_-_url_type] => ext
        [small_ad_4_-_url] => www.google.com
        [facebook] => www.facebook.com
        [twitter] => twitter.com
        [youtube] => www.youtube.com
        [office_address] => text
        [office_address_-_google_url] => test
        [office_-_phone] => 1234567890
        [office_-_800_#] => 8001234567
        [office_-_email] => [email protected])
        
    
Viewing 10 posts - 1 through 10 (of 10 total)