function pretty_field_groups($field) { global $post; $groups = acf_get_field_groups(); $r = array(); $current_id = is_object($post) ? $post->ID : $_POST['parent']; $current_group = _acf_get_field_group_by_id($current_id); foreach ($groups as $group) { $key = $group["key"]; // don't show the current field group. if ($key == $current_group["key"]) { continue; } $r[$key] = $group["title"]; } return $r; }
function _acf_get_field_group_by_key($key = '', $search_trash = false) { // vars $field_group = false; // try JSON before DB to save query time if (acf_is_local_field_group($key)) { $field_group = acf_get_local_field_group($key); // validate $field_group = acf_get_valid_field_group($field_group); // return return $field_group; } // vars $args = array('posts_per_page' => 1, 'post_type' => 'acf-field-group', 'orderby' => 'menu_order title', 'order' => 'ASC', 'suppress_filters' => false, 'acf_group_key' => $key); // search trash? if ($search_trash) { $args['post_status'] = 'publish, trash'; } // load posts $posts = get_posts($args); // validate if (empty($posts[0])) { return $field_group; } // load from ID $field_group = _acf_get_field_group_by_id($posts[0]->ID); // return return $field_group; }
function get_field_group_choices() { // function taken from https://github.com/tybruffy/ACF-Reusable-Field-Group, thank you global $post; $groups = acf_get_field_groups(); $r = array(); $current_id = 0; if (isset($post->ID)) { $current_id = $post->ID; } $current_group = _acf_get_field_group_by_id($current_id); foreach ($groups as $group) { $key = $group["key"]; // don't show the current field group. if ($key == $current_group["key"]) { continue; } $r[$key] = $group["title"]; } return $r; }
/** * Get a field group by its ID * * @param int $id ACF field group ID (post ID) * @return array|bool ACF field group, or false or empty array (depending on the ACF version) if the ID doesn't exist */ public static function get_field_group_by_id($id) { if (self::is_pro_installed()) { return _acf_get_field_group_by_id($id); } else { $field_groups = self::get_all_field_groups(); foreach ($field_groups as $field_group) { if ($field_group['id'] == $id) { return $field_group; } } return false; } }