I am trying to loop through all field groups on a homepage location in the order that my client chose through drag and drop of the field groups on that page’s admin.
How do I override the Order No. value in each group’s admin?
Specifically, how do I get my client’s dragged ‘n dropped order on the page’s admin to dominate?
Custom post order plugins like Simple Page Ordering and Intuitive Custom Post Order don’t seem to have any effect with or without this:
$groups = acf_get_field_groups(array( 'post_id' => $home_ID, 'orderby' => 'menu_order', 'order' => 'ASC' ) );
The order that the boxes are shown is a function of WP and not ACF. This order and the order set in ACF are not related in any way. Each user can reorder the groups and WP will remember that order. On top of this, each post type can have different values. Here’s an explanation of where these can be saved https://wordpress.stackexchange.com/questions/109112/how-does-wordpress-remember-metabox-positions. And to top this off, it will not be different for different posts. If the user drags the groups to reorder them on one page, they will be in that order on all pages. If they reorder them again, that will reorder them for all pages.
Sorry, it is complicated.
Is there a way this can be done? Probably, but it would be a lot of work and I can’t really give specific code that will do it. The solution is not an easy one, nor one that I would use.
You would have to:
acf_get_field_group()is the function you would use
If I needed to give someone the ability to rearrange the order of things I would consider this a good candidate for using flexible content fields.
That’s the logic I had in mind. I wouldn’t even need to get the fields for each group. All I need is to output a client-ordered loop that allows me to conditionally get template parts (with content from option pages).
I could even use multiple select field – the stylized UI is a pretty neat way of adding, removing and ordering items – but I couldn’t work out how to sort that foreach loop either.
A Flexible Content field may well have to be the way to go. I am little concerned that it will result in a complex page and a lack of clarity for my client.
I also wish I could make some layouts read-only layouts (for add-on modules that are available for purchase).
The topic ‘Sorting field groups by drag and drop order’ is closed to new replies.
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!