Home Forums Backend Issues (wp-admin) Reorder ACF Groups (per page basis) Reply To: Reorder ACF Groups (per page basis)

  • You can make it kind of work.

    As you said the problem is that WP saves the order of boxes per post type so when
    used on ‘page’ type post you will have problems when you have different set of fields for the homepage and a generic page.

    On a homepage type of page (post) we can set order like:
    header, homepage fields
    but then when we go to a generic page where we have:
    header, generic fields

    So when the order is set for the homepage by the user like: header, homepage fields, WP saves this to the metafield meta-box-order_page and when you go to edit a generic page, WP tries to sort the meta boxes in order: header, homepage fields.

    Unfortunately there’s no ‘homepage fields’ group here so it only takes ‘header’ to ‘sorted’ set and the ‘homepage fields’ is left in the group where it was at first and that is ‘high’ priority group, then WP writes the metaboxes starting with ‘high’ then ‘sorted’ groups – this way on generic page we get ‘generic fields’, ‘headers’ and on a homepage ‘hompeage fields’ , ‘headers’.

    So the only way I see here is to disable all the sorting for ACF groups, thus leaving them in the initial ‘high’ priority group and relay on the order of the ACF groups in the define ACF groups admin panel section.

    As for disabling this I used the mentioned filter:

    add_filter('get_user_option_meta-box-order_page', 'removeAcfGroupsFromUserSort', 10, 3);
    function removeAcfGroupsFromUserSort($result, $option, $user)
          if (empty($result) || empty($result['normal'])) return $result;
          $metaboxIds = explode(',', $result['normal']);
          $metaboxIdsOut = array_filter($metaboxIds, function($metaboxId) {
            return (!strstr($metaboxId, 'acf-group'));
          $result['normal'] = implode(',', $metaboxIdsOut);
          return $result;