Home › Forums › Backend Issues (wp-admin) › Sorting field groups by drag and drop order
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 useacf_get_fields()
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.
Thanks John.
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).
A layout could consist of a single field, The value doesn’t even matter as long as it has one. Or it could be a select field.
Layout Name: Include Module
with a select field and a list of available modules.
Actually no-field layouts work too.
Each layout is named after a specific module and as I loop through them I load the corresponding template part.
I will just need to hide the Open/Collapse toggle button.
You must be logged in to reply to this topic.
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!
CPT registration is coming to ACF! We demoed the new feature during the most recent session of ACF Chat Fridays. Check out the summary for the details. https://t.co/k2KQ3WWBAz
— Advanced Custom Fields (@wp_acf) March 7, 2023
© 2023 Advanced Custom Fields.
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.