Home Forums Backend Issues (wp-admin) Sorting field groups by drag and drop order


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 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.

  • This reply has been marked as private.
  • 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:

    1. Get the user meta value that holds the order of meta boxes for the post type (page) for the user in question
    2. Loop though this array and find entries that match ACF field groups
    3. For each field group get that field group acf_get_field_group() is the function you would use
    4. Get the field for the group acf_get_fields()
    5. Loop though the field list and display each field, this would probably need some complicated logic depending the fields and how you want to output them

    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.

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

The topic ‘Sorting field groups by drag and drop order’ is closed to new replies.