Support

Account

Home Forums Bug Reports Flexible Content Fields with local json save out of order

Solving

Flexible Content Fields with local json save out of order

  • Has anyone else seen this behavior? When saving a Custom Field Group that is a flexible content, the fields inside of the layout get their order changed. Usually the top items move to the bottom.

    My builds are custom so I don’t usually have many other plugins installed and build using Sage with Roots. I’ve seen the behavior on both sage v8 and v9.

    I think it started with V5 of WP, but not certain. My guess is the local json saving is where the issue happens. I use that as I work with other devs on projects and they also encounter the issue.

  • YES. It’s happening for us very frequently – at least 5 times today that I’ve had this happen for me. Not sure what is going on, but we haven’t been able to track it down to any filter or any plugin, thus far. We’ve built a theme with Sage and did have to use a few filters to change where the acf-json folder is loaded, but that shouldn’t cause any issues.

  • YES. I was beginning to think I was losing it. Glad to know it’s not just me!

    It gets extra messy on my set up too – most of my ~24 flexible layouts use tabs – so if the first field (usually a tab) gets moved to the end, the tabs get all messed up too.

  • This is definately a bug in the import/sync. I have reported it to Elliot. I tried to figure out how to fix it cuz I was in a bind to get something done but I’m completely baffled why the first field in every layout gets pushed to the end.

  • Thanks John! Hope you hear back from Elliot soon!

  • I have figured where the problem is and I have informed E.

    I also have a temporary fix, it’s not pretty but it works.

    file: advanced-custom-fields-pro/includes/acf-field-group-functions.php
    Lines 1032 to 1037 look something like this

    
    // Add field menu_order.
    			if( !isset($count[ $field['parent'] ]) ) {
    				$count[ $field['parent'] ] = 1;
    			} else {
    				$count[ $field['parent'] ]++;
    			}
    			
    			// Only add menu order if doesn't already exist.
    			// Allows Flexible Content field to set custom order.
    			if( empty($field['menu_order']) ) {
    				$field['menu_order'] = ($count[ $field['parent'] ] - 1);
    			}
    

    replace this code with

    
    // Add field menu_order.
    			if (!isset($field['parent_layout'])) {
    				if( !isset($count[ $field['parent'] ]) ) {
    					$count[ $field['parent'] ] = 1;
    				} else {
    					$count[ $field['parent'] ]++;
    				}
    			} else {
    				if( !isset($count[ $field['parent_layout'] ]) ) {
    					$count[ $field['parent_layout'] ] = 1;
    				} else {
    					$count[ $field['parent_layout'] ]++;
    				}
    			}
    			
    			// Only add menu order if doesn't already exist.
    			// Allows Flexible Content field to set custom order
    			if (!isset($field['parent_layout'])) {
    				if( empty($field['menu_order']) ) {
    					$field['menu_order'] = ($count[ $field['parent'] ] - 1);
    				}
    			} else {
    				if( empty($field['menu_order']) ) {
    					$field['menu_order'] = ($count[ $field['parent_layout'] ] - 1);
    				}
    			}
    
  • wow! Great find and thank you for doing so much leg work John!

  • We are in the middle of working on a site, has about 30 layouts in a flex field. I just couldn’t wait any longer as it was causing us huge issues. I know the E has lots of things to worry about so figured I’d see what I could do.

  • FYI, I believe you got file and and line number mixed up.

    advanced-custom-fields-pro/includes/acf-field-group-functions.php

    line 1032

  • correct, I edited my reply to fix.

  • It really isn’t pretty, and I’m sure there is a better way to fix this, but, this works so I’m good with it for now.

  • This bug is really grinding my gears. Any idea when the bugfix will be released? It’s a huge pain in the a** that every developer has to constantly check the diff before committing the JSON file after saving a field group.

  • i believe it was addressed in 5.8.2 Are you still seeing it @mroesele ?

  • Yes. I am experiencing this same exact issue. Updating to 5.8.2 did not seem to help, but I am still testing.

  • I can confirm two things:

    • the bug still exists in the current version 5.8.2
    • the bugfix above (change some code concerning menu_order in acf-field-group-functions.php does not work either

    The JSON file is in the correct order and the acf fields while editing a page are also in the correct order but when I want to edit a field group all fields within the field group are being randomly reordered (always the same fields are affected) and this state will be written into the json file on save.

    This is a very huge problem because editing ACF fields is just unusable right now. Having to reorder multiple fields after changing one property is really slowing down our workflow.

  • Since the update it’s worked fine for me. I just tested on a flexible content field with 23 layouts and a lot of fields in the layouts.

    I don’t have any other ACF Plugins installed. I’d suggest seeing if maybe something else is causing your issue.

  • Can you either provide some simple json field group examples here or send them to the developer by using the contact form https://www.advancedcustomfields.com/contact/ with an explanation.

    When I say simple, if you can test and trim down the groups to just the fields that cause the issue that would be great. That or give a detailed explanation of what fields and what happens will be needed.

    You’re best bet would be to send them directly to the developer because I don’t know how much time I can invest into testing and then sending them to the developer with an explanation as well. It would be better to just cut out the middle man (me) and tell Elliot exactly what is happening.

    You will probably need to put any .json files into a .zip file to be able to send them.

  • This, unfortunately, is an issue for us as well. I’ve disabled all plugins and reverted to the default twenty nineteen theme on the site we’re currently developing and trying to save the field group is resulting in this same field reordering issue. All plugins are up to date, as is WordPress core. Not sure what’s going on here, but I’m happy to send over the JSON file for this field group that we’re having problems with.

  • I have been doing some testing on a site that is having a sync issue with fields being out of order. Not specifically with flex fields but with all fields. I have found that most of it is plugin conflicts, running just ACF on a site I am not seeing any issues, but I have not tested flex fields yet.

    Anyway, you need to look at other plugins on the site and test to see if it goes away with some of them deactivated. Look at any ACF add ons you may have running.

    The ACF Enhance Message field is a definite problem. If you’re using this you need to get rid of it. I’ve found that I can replace this plugin by using an acf/prepare_field filter for a standard message field which did not exist when started using this one.

    Also, my ACF To Content plugin available on github is an issue. I have corrected the problem with this one if you update.

    In particular, if you are looking for others. Any plugin or code that alters or updates a post of any kind on any hook but is not checking specific post types. These plugins must check to see if the post type is acf-field or acf-field-group and if it is then they should return without making changes. Any alteration to the values stored in wp_posts will cause issue in ACF.

  • We can confirm that this issue is also occurring for us on ACF 5.8.3. We performed the following patch to /advanced-custom-fields-pro/includes/acf-field-group-functions.php:1029:

    
    /**
     * 20190809 MONKEYPATCH
     * There is a bug causing fields to lose their ordering specified in the local-json files.
     * The fix below addresses this until Elliot releases a fix.
     * See: https://support.advancedcustomfields.com/forums/topic/flexible-content-fields-with-local-json-save-out-of-order/
     */
    //             // Add field menu_order.
    //             if( !isset($count[ $field['parent'] ]) ) {
    //                 $count[ $field['parent'] ] = 1;
    //             } else {
    //                 $count[ $field['parent'] ]++;
    //             }
    
    //             // Only add menu order if doesn't already exist.
    //             // Allows Flexible Content field to set custom order.
    //             if( !isset($field['menu_order']) ) {
    //                 $field['menu_order'] = ($count[ $field['parent'] ] - 1);
    //             }
    /**
     * 20190809 BEGIN FIX FROM
     * https://support.advancedcustomfields.com/forums/topic/flexible-content-fields-with-local-json-save-out-of-order/
     */
                // Add field menu_order.
                if ( ! isset( $field['parent_layout'] ) ) {
                    if ( ! isset( $count[ $field['parent'] ] ) ) {
                        $count[ $field['parent'] ] = 1;
                    } else {
                        $count[ $field['parent'] ]++;
                    }
                } else {
                    if ( ! isset( $count[ $field['parent_layout'] ] ) ) {
                        $count[ $field['parent_layout'] ] = 1;
                    } else {
                        $count[ $field['parent_layout'] ]++;
                    }
                }
    
                // Only add menu order if doesn't already exist.
                // Allows Flexible Content field to set custom order
                if ( ! isset( $field['parent_layout'] ) ) {
                    if ( empty( $field['menu_order'] ) ) {
                        $field['menu_order'] = $count[ $field['parent'] ] - 1;
                    }
                } else {
                    if ( empty( $field['menu_order'] ) ) {
                        $field['menu_order'] = $count[ $field['parent_layout'] ] - 1;
                    }
                }
    /**
     * 20190809 END MONKEYPATCH
     * https://support.advancedcustomfields.com/forums/topic/flexible-content-fields-with-local-json-save-out-of-order/
     */
    

    We can confirm that this is the same thing posted by @hube2, and that it fixed the issue for us. Hopefully this information is helpful in developing a permanent fix, or to others who are testing the issue.

  • I’ve tried disabling all plugins and using the standard theme – I’m still having this issue. We don’t have any hooks that are firing on save_post, etc. The weird thing is that the fields are in order when editing my custom post types after the field groups are synced, BUT the edit view for the field group is all out of order, which then causes the actual fields to be out of order when I go to save it.

    See the screenshots attached. First one is the out of order field group, second one is the edit screen for my CPT that does have the fields in the correct order.

  • @matt-anchour this is exactly what we are experiencing over here.

    the JSON file is being interpreted correctly while using the “edit post” screen but gets messed up while loading the “edit field group” screen. Saving the field group then results in a messed up JSON file.

    Hopefully a bugfix is being released soon.

  • Same thing here, even in just released version 5.8.4 Viewing actual fields show in proper order. But when editing, within a repeater (and all children repeaters) the fields within reverse order. Top level items don’t reverse (but only testing with one file right now).

    With 5.8.3 the order of top level and repeater items would be random, or sometimes simply reversed.

  • To combine the fixes from both threads, I replaced:

    
    // Add field menu_order.
    if( !isset($count[ $field['parent'] ]) ) {
            $count[ $field['parent'] ] = 1;
    } else {
            $count[ $field['parent'] ]++;
    }
    
    // Only add menu order if doesn't already exist.
    // Allows Flexible Content field to set custom order.
    if( !isset($field['menu_order']) ) {
            $field['menu_order'] = ($count[ $field['parent'] ] - 1);
    }
    

    on lines 1029-1040 of acf-field-group-functions.php with

    
    // Add field menu_order.
    if (!isset($field['parent_layout'])) {
        if( !isset($count[ $field['parent'] ]) ) {
            $count[ $field['parent'] ] = 1;
        } else {
            $count[ $field['parent'] ]++;
        }
    } else {
        if( !isset($count[ $field['parent_layout'] ]) ) {
            $count[ $field['parent_layout'] ] = 1;
        } else {
            $count[ $field['parent_layout'] ]++;
        }
    }
    
    // Only add menu order if doesn't already exist.
    // Allows Flexible Content field to set custom order
    if (!isset($field['parent_layout'])) {
        if( empty($field['menu_order']) && $field['menu_order'] !== 0) {
            $field['menu_order'] = ($count[ $field['parent'] ] - 1);
        }
    } else {
        if( empty($field['menu_order']) && $field['menu_order'] !== 0) {
            $field['menu_order'] = ($count[ $field['parent_layout'] ] - 1);
        }
    }
    
  • To combine the fixes from both threads, I replaced:

    
    // Add field menu_order.
    if( !isset($count[ $field['parent'] ]) ) {
            $count[ $field['parent'] ] = 1;
    } else {
            $count[ $field['parent'] ]++;
    }
    
    // Only add menu order if doesn't already exist.
    // Allows Flexible Content field to set custom order.
    if( !isset($field['menu_order']) ) {
            $field['menu_order'] = ($count[ $field['parent'] ] - 1);
    }
    

    on lines 1029-1040 of acf-field-group-functions.php with

    
    // Add field menu_order.
    if (!isset($field['parent_layout'])) {
        if( !isset($count[ $field['parent'] ]) ) {
            $count[ $field['parent'] ] = 1;
        } else {
            $count[ $field['parent'] ]++;
        }
    } else {
        if( !isset($count[ $field['parent_layout'] ]) ) {
            $count[ $field['parent_layout'] ] = 1;
        } else {
            $count[ $field['parent_layout'] ]++;
        }
    }
    
    // Only add menu order if doesn't already exist.
    // Allows Flexible Content field to set custom order
    if (!isset($field['parent_layout'])) {
        if( empty($field['menu_order']) && $field['menu_order'] !== 0) {
            $field['menu_order'] = ($count[ $field['parent'] ] - 1);
        }
    } else {
        if( empty($field['menu_order']) && $field['menu_order'] !== 0) {
            $field['menu_order'] = ($count[ $field['parent_layout'] ] - 1);
        }
    }
    
Viewing 25 posts - 1 through 25 (of 28 total)

The topic ‘Flexible Content Fields with local json save out of order’ is closed to new replies.