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.

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

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.